Skip to main content
Known Participant
February 1, 2017
Question

Determine if same document is opened

  • February 1, 2017
  • 4 replies
  • 795 views

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 has been closed for replies.

4 replies

Legend
February 2, 2017

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

Legend
February 1, 2017

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

Known Participant
February 2, 2017

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.

Legend
February 1, 2017

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

Legend
February 1, 2017

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

Known Participant
February 1, 2017

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

Known Participant
February 1, 2017

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.