These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How do I update PDF content with Javascript?

KentYang
Registered: Jul 23 2008
Posts: 7

Hello,guys

We want to craet a form in PDF. The content of this form has to follow the XML file which is embeded in PDF as an attachment. Therefore, when we update the XML, the form should also be updated automatically. Can JavaScript have the ability to do this? We try to get the path of the embeded file, but failed.

This is the reference we find on this community: Please take a look of the PDF "Bill of Materials"from Adidas
http://www.acrobatusers.com/tech_corners/3d/3d_gallery/index.php?galleryimage=3

We also analysised a lot of samples, but can't get the script which is embeded inside the "Defult Script" when we import a 3D object into PDF.

These two problems are critical to our research, thanks for your help!
Best Regards,

My Product Information:
Acrobat 3D 8.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In Acrobat JavaScript, attached files are refered to as "Data Objects". To access an XML attachnment in a PDF use the "doc.getDataObjectContents()" fucntion. This returns a byte stream object that can be converted to a string and parsed with either the "XMLData" object or the Core JavaScript X4E fucntionality.

To get an attachment's data:

var stmDO = this.getDoatObjectContents("MyXML");
var strXML = util.stringFromStream(stmDO);
var oXML = XMLData.parse(strXML);

The "XMLData" object does not handle namespaces.

Here's a sample file that shows more of how to do this:
http://www.windjack.com/PDFSamples/XMLDataObjDemo.pdf

For the JS code to work the attached file must have a DataObject Name. The only way to do this is to write JS code to import the XML attachement, you can't do it from the Acrobat UI.

As for 3D. Once the script is attached to the 3D Annotation, there is no UI in Acrobat for editing or extracting it. It's a one way trip. The only way to extract the script is with a tool like PDF CanOpener

http://www.windjack.com/products/pdfcanopener.php

, which is a PDF COS level editor.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Sounder
Registered: Nov 26 2008
Posts: 3
Hello KentYang,
you might as well speak to us directly.

Best Regards,
Helmut Klinger
CEO

www.vpr-solutions.de