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.
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
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:
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.
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¶m2=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 ?
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.
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();
It's how you should do it ? Whatever button it is ? (classic, mail or HTTP submission)
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.
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.
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 ).
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 ?
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 ?
Thanks again for your fast answers !
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.
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 ?
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?