Link to home
Start Free TrialLog in
Avatar of mollylab
mollylab

asked on

How to populate and read fields in PDF form using Javascript iframes.

Hi -
I have a Web app written in javascript with iframes.  I want to use a fillable PDF form that I can auto-populate with the user's name in javascript and then read the fields that the user populates.   The process flow would be: (1) user logs into web application (2) user selects "complete form X"  (3) the pdf form X would open in Adobe Acrobat (preferably in an iframe) (4) the web app javascript would populate the user's info in the appropriate pdf fields (5) the user would fill in the other pdf fields (6) user would select "submit" button on pdf form (7) web app javascript would read the other pdf fields that the user populated (8)  pdf form X would close (9) web app would complete with the data entered.

From what I gather on the Adobe site this is not possible to do.    I can export the fields to an XML and email it from the PDF,  but I really want to read them.  I don't understand why I cannot populate some fields either.   I have Adobe Acrobat 8 Professional that I am using to build the PDF form.

I appreciate any tips you can provide.
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Likely a security issue
Can you load the PDF with the values in the query string? Those values should then be available to the code in the pdf
Avatar of mollylab
mollylab

ASKER

mplungian - Thank you for your comment.   I'm not sure what you mean by the "query string".  I can open the PDF in an iframe  <iframe src="filename.pdf">, but I could not find a way to add arguments/ values to the src.      Even if I could, I still don't have a way of reading the fields in the PDF after it is populated.   Since I'm not finding a solution anywhere, I'm concluding that this just cannot be done.
Query string is what comes after the ?
Filename.pdf?parm1=value1&parm2=value2

My code is:

<iframe id="MAIN" name="MAIN" style="visibility:hidden;position:absolute;height:2650px;width:1000px;left:0px;top:32px" src="td1_11282011.pdf#toolbar=0&navpanes=0&scrollbar=0&Lastname=Smith" frameborder="no" marginwidth="0" marginheight="0" scrolling="no"></iframe>

Note that  toolbar, navpanes, & scrollbar are all predefined args that define the PDF frame.  I added "&Lastname=Smith" where "Lastname" is a field defined in the PDF.    I do not get an error, but nothing is displayed in the field.
It of course does not work like that. You need a little more work. I'll see if I can find a PDF script you need to add inside the PDF
First link I googled searching for
JavaScript access query string in PDF
gave
http://blogs.adobe.com/pdfdevjunkie/2009/12/populating_pdf_form_fields_fro.html


mplungjan:  Thank you for your help, but I still don't think it is possible to do what I want.   I was able to add javascript to the PDF so that it read an argument from the URL (ie mypdffile.pdf?lastname=mollylab) and would display the "lastname" via an "alert", but I could NOT overwrite the "form_lastname" field in the PDF form with the data from "lastname".   Not sure why, but regardless, I want to open the PDF form in an <iframe>, not in a new window.   I have the "lastname" in the HTML code and want to pass it to the PDF form.   I've been searching the Adobe documentation and found this in the Acrobat Javascript Scripting Guide:
Acrobat Javascript does not have access to objects within an HTML page.  Similarily, HTML Javascript cannot access objects within a PDF file.
HTML Javascript is able to manipulate such objects as Window.  Acrobat JavaScript cannot access this particular object but it can manipulate PDF-specific objects.

I think that if it were possible to do what I want to accomplish I would have easily found others that did the same thing.   Adobe Acrobat Pro with LiveCycle Designer is a powerful tool, but does not interface with anything else.

An iFrame IS a new window - so if you pass the value to the URL, the PDF can read and populate
As I stated before: I was able to add javascript to the PDF so that it read an argument from the URL (ie mypdffile.pdf?lastname=mollylab) and would display the "lastname" via an "alert", but I could NOT overwrite the "form_lastname" field in the PDF form with the data from "lastname".

The question is: Is it possible to read and write into a PDF Form that was created using Adobe Pro 8 LiveCycle Designer?    I wrote Javascript that can read the value from the URL, but how do I get it to populate the Form?    The PDF Javascript I wrote does not recognize the Form's field name "form_lastname".
How exactly are you accessing the field?
I expect something  like
this.forms["form_name"].fieldname.value
SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That is the same link you posted on 12/20/11.  I've read it.
And used it exactly as described?
I have not seen any code from you that looks like the code in the link
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.