Does PDFTron insert custom calculation script into a generatedPDF with Doc.InsertPage

We use PDFTron PDFNet SDK in our application for a variety of reasons.

The task I am trying to accomplish is to generate a new PDF by inserting pages (PDFdoc.Insert) from an existing PDF that has custom calculation script (javascript) embedded in the text field properties.

What should happen:
When the client opens the document the calculation on the form should add todays day and the clients name (like a timestamp).

What actually happens:
The javascript remains as plain text.

The custom calculation script (javascript) is not set, when opening the document with a PDF editor and examing the tree / node view I can tell the javascript is indeed in the new generated document and looks to be referenced to the page correctly but opening the PDF with acrobat shows that the custom calculation script has not been set, any ideas or is there something obvious I'm missing?

pdfdoc.InsertPages() copies pages from one PDF to another including any Actions & JavaScripts that may be used on these pages. It does not copy document level actions (or JavaScript that executes when a document is opened, closed, etc).

You would need to manually copy/import these actions (e.g. with pdfdoc.GetSDFDoc().ImportObj(action.GetSDFObj(), true)) and associate them with the new document:

Action doc_open_action = new Action(imported_action_dict);

For specifics, please send the file to support at pdftron.

Thanks for the swift reply.

Looking into it with your explanation in mind and the PDF reference manual, it turns out the AcroForms > CO dict (dictionary that handles interactive form calculations) wasn’t being formed, because we are only taking the page. So what I did to fix this was to rebuilt the dictionary after copying the pages over.

Many thanks for the help.

  • Simon