Parse FDF response

I am trying to populate a field with a php response. I am able to call a javascript, however I would like to populate an existing field with the result of the submitForm method.

so actually

%FDF-1.2
1 0 obj
<<
/FDF
<</JavaScript << /After (myfunction('myvalues'))
>>
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF

works. But I would like to populate the field "response" with some text, for example, is that even possible?


Maschio Andrea


3 Answers

Voted Best Answer

Yes, that is possible. To populate fields is actually the main use for FDF files.

Here is a sample FDF that sets the field "response" to some text:

%FDF-1.2

%âãÏÓ
1 0 obj
<<
/FDF
<<
/F(blank.pdf)
/Fields
[
<<
/T(response)/V(This is some text)
>>
]
/ID[<C9FEDC2BCE3A45D8B61F95F660C49283><5CE2EAA88EE046B182325A1D488989D
D>]
/UF(blank.pdf)>>
/Type/Catalog>>
endobj
trailer
<</Root 1 0 R>>
%%EOF


As you can see, the /Fields array is used to for key/value pairs that represent form fields. So, add a /Fields element to your FDF at the same level as your /JavaScript, and it should work - assuming that you have a field with the name response in your document.

You posted this question in the category "Take PDF Mobile" - are you planning on using this solution on a mobile device? That may not work, you would need a client that supports both FDF and in your case JavaScript.


By Karl Heinz Kremer   

Why not use a format that is slightly easier to deal with, such as XFDF?

But if you want to stick with FDF you have some options

The official FDF Toolkit by Adobe:
http://www.adobe.com/devnet/acrobat/f...

the NK, third party toolkit
http://www.nk-inc.com/

And Here is a PHP Example:
http://phpbootcamp.com/articles/fdf.htm

Also, as Karl said, currently you can't prefill forms on a mobil device with the current set of viewers. Mobile is still too new. You would need to write your own app. Which is perfectly possilbe. There are vendors offering PDF libraries for mobile.


Thom Parker
The source for PDF Scripting Info pdfscripting.com
All About PDF Stamps in Acrobat and Paperless Workflows - THE BOOK !!

The Acrobat JavaScript Reference, Use it Early and Often

The most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)

Having trouble, Why Doesn't my Script Work


Thom Parker   

Thom, Karl, thank for your answers.

I am actually trying to make javascript work in mobile with PDF Expert, which supports a fair subset of acrobat javascript. However, to supply the missing or partially implemented app.openDoc method, which in their implementation returns null, I was trying to use a sort of middleware to make pdf work together in PDF Expert. However I noticed that while submitForm actually workks, the fdf response doesn't seems to be properly parsed, or anyway I cannot populate that fields using this technique.

Thom: could you be more specific about iOs libraries which parse javascript? I am mainly an iOs developer, so that could be a nice way to explore.

Another question about fdf: is there anywhere a good tutorial or sheet about fdf formatting/specifications? I'm talking about a guide which is not a complete reference, just to quick start.

Thanks

Andrea Maschio


Maschio Andrea   


Please specify a reason: