Skip to main content
Inspiring
June 26, 2023
Answered

ASFileAcquirePathName returns UNIX-style pathname on Windows

  • June 26, 2023
  • 2 replies
  • 595 views

I am trying to get the pathname of the active document in Acrobat using the following:

 

ACCB1 std::string ACCB2 GetActiveDocumentFilename() {
 
AVDoc activeDocument = AVAppGetActiveDoc();
if (!activeDocument) {
return "";
}
PDDoc document = AVDocGetPDDoc(activeDocument);
if (!document) {
return "";
}
ASFile file = PDDocGetFile(document);
if (!file) {
return "";
}
ASPathName filePath = ASFileAcquirePathName(file);
if (!filePath) {
return "";
}
 
return ASFileSysDIPathFromPath(NULL, filePath, NULL);
}

 

However, the pathname I get is (for example) /D/Documents/Testing/Test.pdf

 

Is there a way to get a Windows-formatted path/filename?

 

Cheers

Pete

This topic has been closed for replies.
Correct answer Petej

I used ASFileSysDisplayStringFromPath

2 replies

Legend
June 26, 2023

That is only superficially Unix style. What it actually is, is a DIPath (Device Independent Path) which is what is stored inside a PDF for links etc, and what Acrobat always uses internally. But...this code is fundamentally wrong because it treats an ASPathName as a string. Yes, sometimes it is, and sometimes it is binary data which would crash your plug-in. You need to treat an ASPathName as an opaque pointer, and pass it to an API (with the ASFileSys) for conversion. I think you may already have solved that, but it's important to mention it.

PetejAuthor
Inspiring
June 26, 2023

Thanks for the info, yes I dug a bit further into the documentation and found that method.

PetejAuthorCorrect answer
Inspiring
June 26, 2023

I used ASFileSysDisplayStringFromPath