Skip to main content
Known Participant
Feb 1, 2017 12:42 PM UTC
Question

Determine if same document is opened

Hello,

I have developed a plugin to open a document from the document path received from external program.

Is there any way to avoid reloading the document when same document is opened twice.

Here is my code snippet:

ACCB1 void ACCB2 OpenDocument()

{

AVDoc avDoc = AVAppGetActiveDoc();

PDDoc pdDoc = AVDocGetPDDoc(avDoc);

char filePath[256];

GetPrivateProfileString("OpenFile", "filePath", "", filePath, 256, iniFilePath);

ASAtom pathType = ASAtomFromString("Cstring");

//Create an ASText object

ASText titleText = ASTextNew();

ASTextSetPDText(titleText, "This PDF was opened by using the Acrobat SDK");

//Create an ASPathName object

ASFileSys fileSys = ASGetDefaultFileSysForPath(pathType, filePath);

ASPathName pathName = ASFileSysCreatePathName(fileSys, pathType, filePath, NULL);

//Open the PDF file

AVDoc myDoc = AVDocOpenFromFile(pathName, fileSys,NULL);

//Do some clean up

ASFileSysReleasePath(fileSys, pathName);

ASTextDestroy(titleText);

}

Thanks

This topic is closed to new replies. Start a new post to keep the conversation going.

8 replies

Legend
Feb 2, 2017 9:43 AM UTC

But what if the user has opened a document themselves? Including the possibility of browser integration?

Translate
Legend
Feb 1, 2017 2:11 PM UTC

Your checking code looks ok but you do not say how you call it. Do you enumerate all open AVDoc?

Translate
Known Participant
Feb 2, 2017 5:37 AM UTC

No. I do not have to enumerate all open AVDoc.

At any time, there will be only one document opened in the Acrobat as I don't want to open new window for each document.

Translate
Legend
Feb 1, 2017 1:29 PM UTC

is there a problem (edited) with my solution in your previous similar question? Seems that it will work.

Translate
Legend
Feb 1, 2017 1:27 PM UTC

It shouldn't open twice. What do you see?

Translate
Known Participant
Feb 1, 2017 1:29 PM UTC

I can see the reloading of the document if the document is same.

Translate
Known Participant
Feb 1, 2017 1:49 PM UTC

Hello,

I did some workaround on this.

Before opening any new document, I am checking the path of the document that is already opened like this:

ASFile pdffile = PDDocGetFile(pdDoc);

ASFileSys fileSys = ASFileGetFileSys(pdffile);

ASPathName pathName = ASFileAcquirePathName(pdffile);

CString strDocPath = ASFileSysDisplayStringFromPath(fileSys, pathName);

And if so, I do nothing otherwise I open the other document.

If there is any glitch, please let me know.

Thanks.

Translate