PDF Form - Load and Save from/to XML

Avatar

Avatar

DevSgl72

Avatar

DevSgl72

DevSgl72

26-03-2010

Hello,

I'm looking for a solution to fill and read fields value from a PDF form. I am working with Microsoft Framework 2.0 and C# for a desktop application.

For the moment I'm using a FDF file for filling the PDF fields and iTextSharp to read back fields values once the PDF is saved. But it's not working with some PDF that are bind to a XML datasource. The idea is to drop the FDF solution and try using the XML instead.

So I have a PDF Form (myPdf.pdf) with fields binded on a XML datasource (XSD schema file myPdf.xsd).

I have a XML data file (myPdf.xml) in the same directory as the PDF file.

With LiveCycle and JavaScript is it possible to :

  • Load the XML data file and fill the PDF when I open the PDF file ?
  • Export the fields value into the XML when closing or saving the PDF file ?

If not possible with LiveCycle and JavaScript, do you know any other solution ?

I was thinking about putting a "Send by HTTP" button and use a listener on localhost to get the data, but I need to listen on a particular port and there is a little chance that this port is already used by something else. I'm really not lucky in this case but it could happen. And since the port is "hard coded" in the PDF I have no way to change it if needed. Or I haven't found how to.

Thanks for your answers

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

26-03-2010

Yes you can launch the xml file (like the FDF) and it will load th eform as well. To see what you have to do .....put a button on your form and add the code:

xfa.host.exportData()

to the click event. Now render your form, fill it out, and hit the button. It will ask you for a file name (it will also put an extension of XDP onto the file). This is the xml data file (named as an xdp file). Open it in an xml editor and you will see near the bottom the reference to the template. Now if you launch the xdp file it will open Acrobat and launch your form and merge the data onto the form. Note, if Designer was installed after Acrobat, then the XDP extension is registered to designer (it thinks this is a native template file) and you will get an error. Make sure the xdp extension is registered to Acrobat.

For the saving, you can programmatically click the submit button whether it is visible or not.

Paul

Answers (10)

Answers (10)

Avatar

Avatar

DevSgl72

Avatar

DevSgl72

DevSgl72

30-03-2010

Like I said, I'm back ^^

I manage to get the HTTP request when I click the send button. I have all the fields and values in a query string (param1=value1&param2=value2&...).

Now it seems Adobe Reader is waiting for a specific answer. I think you have to say him "it's ok, I have got all the data" or "oh dude, I can't read this at all" or something like this. But I didn't found the HTTP response I need to use. Do you know what Adobe Reader is waiting for ?

For the HTTP send button it seems you can't configure the URL dynamically (no binding possible). I will use http://localhost:myPort, but it would be nice if I could set the URL info in the XDP and retrieve it in order to configure the button. Any idea to do this ?

Thanks.

Avatar

Avatar

DevSgl72

Avatar

DevSgl72

DevSgl72

26-03-2010

If I must add a button on the form I will do it and if I have a Form with lot of pages, I need to put a button on each page so the user don't have to look for the button. The save button in Reader is always at the same place that's why I would like to use it, the user know where to find it.

But looking at your answer it seems to be impossible to do.

For the loading it's ok with the XDP file. I just have to set the value in the XML and it rocks.

For the saving I will test the HTTP button. I find how to close the PDF (app.execMenuItem("Close")), but is seems it's impossible to close Reader (same security problem with exporting XDP with filename as parameter).

I will have to do some tests now. Thanks for your answers, maybe I will come back later

Edit : I didn't test with Acrobat Reader but Acrobat Pro, and exportData don't work with Acrobat Reader ... so HTTP button is my only chance for now.

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

26-03-2010

The post save is too late .....how does the user indicate that they are done. Why not have a close button on the form and when they click the button do the save then close the form yourself?

Paul

Avatar

Avatar

DevSgl72

Avatar

DevSgl72

DevSgl72

26-03-2010

You're right, I will look with the certificate at another time.

The option for the moment would be to call a send to HTTP button when the postSave event of the PDF document is raised. For the moment I'm testing with a classic button for exporting the data.

So in my button click event I have done : xfa.host.exportData();

And in the form postSave event I have done : myButton.execEvent("click");

It's how you should do it ? Whatever button it is ? (classic, mail or HTTP submission)

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

26-03-2010

You are right about the certification, but that has its own challenges. Certifying the form is not the issue, but each user woudl have to have the cert that you signed with in their trusted store for certification to work. If this is limited to a small number of machines that you control then it is not too bad. If this is a public domain application then people will balk at having to add a cert into their trusted store.

Paul

Avatar

Avatar

DevSgl72

Avatar

DevSgl72

DevSgl72

26-03-2010

The documentation say that the PDF need to be certified to be able to use exportData with a parameter. You need to sign the PDF with a certificate or something like this ? I don't want to use a send by HTTP button ^^

As for the node dataDescription, I can keep it after all. It won't change unless the XSD change so it safe and easy to change this part if I need to.

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

26-03-2010

As mentioned earlier you cannot save the data unattended. If you pass a parameter for the filename you will get a security error (in the javascript console). If you do not pass a parameter then the user can pick the file and as the user is aware that data is being saved (as they are picking the filename) then it is OK.

I wouldn't remove anything in the xdp file. That node is there for a reason (other LC services use it) and although you may not need it now you don't want to paint yourself into a corner (just my opinion ).

Paul

Avatar

Avatar

DevSgl72

Avatar

DevSgl72

DevSgl72

26-03-2010

Ooooh nice !

I have tried to change the exportData with : xfa.host.exportData("filename.xdp")

But nothing happen. Without parameter I have the dialog showing up. Do you know why ?

I suppose there is a JavaScript variable/constant with the PDF file name so I could do : xfa.host.exportData(pdfFileName + ".xdp")

The idea is to save the xdp file in the same directory and with the same name of the PDF file.

In the XDP there is a dd:dataDescription XML element. Seems it does no harm when deleted. Can you confirm it ?

After all the above, the last thing would be to call the click of this button when saving the PDF. There is events when you save the PDF from Reader ?
Nevermind, just found them (postsave, preSave).

Thanks again for your fast answers !

Avatar

Avatar

DevSgl72

Avatar

DevSgl72

DevSgl72

26-03-2010

Does this sound acceptable?

I would say know but it's true that I didn't mention this point.

The only user interaction should be saving the PDF without asking him anything if possible.

  • The PDF is launched from the desktop application
  • The user fill the form, add or modify information
  • The user Save the PDF and close Adobe Reader (or close Reader which ask to save the PDF)
  • I read back the fields values (with iTextSharp for the FDF solution / from the XML data file for what I'm looking for)

For saving I should be able to do with a "Send by HTTP" button, but only if I can click this button with JavaScript when saving the PDF or closing Adobe Reader. Impossible to do for the last one I think ^^

For the loading, this sound good. So you can have a XML with a link to the PDF and when loading the XML, Adobe Reader get the PDF and fill it ? Like with a FDF file then ?

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

26-03-2010

Yes you can import and export the xml data to and form the form. In Acrobat/Reader there is a menu item that will do this for you. Look under the Forms/Manage Forms Data option. These will require your user to select the file they want to use. If you interested in a more jands off approach, then you will be dealing with security issues (do unattending operations on the users behalf that involve operations outside of the viewer is viewed as a security risk - hence the user must know about them). For the import the data file can carry a link to the form template and as such if you launch the data file, then the template can be found and loaded (with data). For the exit unfortunately you cannot make it unattended. You can bring up the save dialog but the user will have to enter the data filename to save it under.

Does this sound acceptable?

Paul