Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

DocJavaScriptAction function

Question

I'm facing some strange problem with QP's DocJavaScriptAction function. I used this function to set following simple JavaScript code on "Document Close" (WC):

app.alert("This is a test message on Document Close");

I tested saved PDF in Adobe Reader 9 as well as 10 and it works only in special scenario. It's little complex for me to explain here, but I will give you my action steps to tell you when it works and when it does not.

Situation when it DOES NOT work:

  • Open the PDF File saved by QP by double click.
  • File Opens correctly in Adobe Reader.
  • Close PDF File. Here the message was expected to show, but it didn't.

Situation when it WORKS:

  • Open the PDF File saved by QP by double click.

  • Go to "Edit - Preferences" menu. This will show the "Preferences" window.

  • Don't make any changes; simply click the "Cancel" button to close the Preferences window.

  • Now, close the PDF... guess what! The JavaScript Alert window starts showing.

This persists till I close the Adobe Reader Application. I mean, if I just close the PDF file document from the small "x" placed in line with the menu bar in top right corner of Adobe Reader and then reopen the PDF file, the JavaScript Alert window shows properly on Document Close. This time, I don't need to perform that "Preferences" window trick. However, as soon as I close the Adobe Reader application and attempt to reopen the PDF file, the issue of not showing JavaScript Dialog persists.

I cannot consider this as an error in Adobe Reader application because I've another application which adds similar code to the PDF File and it works well in same Adobe Reader application. This application uses some other lib; I don't see it ethically correct to mention name of another PDF Lib in QP's forum, so I'm avoiding it to mention here.

The code itself does not have any error either, because it works well when I add the same code to the Document Open even using "SetOpenActionJavaScript" function in Adobe Reader application.

Please tell me this is a bug in QP. If not then can someone please show me the right way to use DocJavaScriptAction in VB6?

Answer

I don't think this is a bug in Quick PDF Library because I was able to replicate the same issue without ever using Quick PDF on the PDF. I've been able to replicate the same issue in Acrobat using a PDF that I created in Acrobat and a PDF that I created in Nitro PDF. Strangely enough, Acrobat and Adobe Reader seem to sometimes have trouble firing the WC event when a document is closed.

Acrobat works sometimes and other times it does not. The fact that it works after you go to Edit > Preferences and then Cancel, is an indication that something is amiss in Acrobat.

The one PDF that you sent through which did always work with the WC event in Acrobat also included an OpenAction entry (which did not include any JavaScript). It seems as if the presence of this OpenAction entry brings the JavaScript handler to life and makes it ready for when the WC event is triggered.

Note that all of the PDF files that I tested worked correctly in Nitro PDF. It was only Acrobat which was having the issue.

So the trick to get Acrobat to work correctly with the WC event is to add an OpenAction to the document. It does not need to have any JavaScript associated with it. It just needs to be present.

For example in C# you would do this:

QP.DocJavaScriptAction("WC", "app.alert(\"This is a test message on Document Close\");");
QP.SetOpenActionJavaScript("// optional JS here");
QP.DrawText(10, 700, "DocJavaScriptAction Test");
QP.SaveToFile("test.pdf");

It's a very strange issue but I'm confident that Quick PDF Library is not the cause beause I could replicate the problem when I was using only Acrobat itself to create the PDF and add the Set Document Action JavaScript event.


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum