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

Importing XML Data from a Database

srprice
Registered: Sep 19 2007
Posts: 138
Answered

I am trying to write a script that executes on Page Open that will automatically update fields with values from a Database. The Database will output an XML file for import.

I have successfully imported XML data but what I need to do is import the data from a URL.

Can someone point me in the right direction?

Thanks in advance for your help.

Sarah

My Product Information:
Acrobat Pro 8.1.2, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If the database is remote, then you're best strategy is to write a server script to return the data in response to a submitForm action from Acrobat.

A PDF submit to an URL generates an HTTP PUT Request. Acrobat expects to see return data in the HTTP Response generated by the server script at the URL.

So, your Page Open script would call "doc.submitForm()", which sends out an HTTPRequest to a server script, which packs the return data into the body of the HTTPReponse (with correct MIME type) and sends it back to Acrobat. If Acrobat recognizes the return data format, it merges it into the form.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

srprice
Registered: Sep 19 2007
Posts: 138
I am assuming that the correct data type would be an XFDF file??

We are in the process of writing a PHP script to perform this task.

Do you by any chance know where there might be some type of API reference document for this type of scripting?

Thanks for your help.

Sarah
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
XFDF is an excellent data type to use. But as for writing server scripts for Acrobat, there isn't much out there. If you search the forums for "PHP" and/or "Server Script" you'll get lots of hits. Some of which contain useful PHP code.

I written a little on this topic, but not a whole lot. I'll be writing some real articles and scripts for server side data handling later this year. But right now your best strategy is to watch what comes down to the PHP script when you submit data from Acrobat and then send back your data in a similar format. The most important thing is to set the return Content-type correctly.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

srprice
Registered: Sep 19 2007
Posts: 138
Can you tell me what the correct MIME type is for XFDF?

Thanks, Sarah
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well, thats why you need to watch the content-type when Acrobat submits data. If you submit XFDF, Acrobat will fill in the HTTP header parameters with what it expects in the return data.

But I believe this works: "application/vnd.adobe.xfdf" or "application/vnd.xfdf"

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

nixopax
Registered: Feb 6 2009
Posts: 105
Hi there Scopley, as Thom replied, those are the mime-type headers. To implement them you would do:

<?phpheader("HTTP/1.0 200 Ok");header('Content-type: application/vnd.fdf'); // Or xfdf?>

The important thing to note when you use the header() function in PHP is that absolutely NOTHING is sent previous to it. Not even a single whitespace. So you can do your server calls, call your info from the database, and then call the headers. After that it's all a matter of outputting the data. Currently, I just do plaintext output with PHP echoing out the variables in the FDF as needed.