If we've already captured the user information, is there a way to programmatically fill in a PDF form?
Copy link to clipboard
Copied
If we've already captured the user information, is there a way to programmatically fill in a PDF form (e.g. using an API)?
Copy link to clipboard
Copied
You need to be much more specific than that... How did you capture the user information? In what environment and using what technology?
Copy link to clipboard
Copied
Our application is a Ruby on Rails application hosted on AWS. We've captured the user information and it's stored in our Postgres SQL database.
For example, we've already captured the information necessary to fill out the blank form fields for the W-9 form at https://www.irs.gov/pub/irs-pdf/fw9.pdf. Via our RoR app, we'd like the user to be able to click a "Send me the completed W-9 form" button, our RoR application auto-fills in this pdf form with the user's information stored in our database, then returns a completed form to the end user (e.g. completed form gets downloaded into their "Downloaded" folder on their PC).
Copy link to clipboard
Copied
It's not so simple... This form was created using LiveCycle Designer. If you want to import data to it you can't use an FDF file, only XML/XDP/XFD. And there are not many applications that know how to do it correctly.
Copy link to clipboard
Copied
You can try generating an XDP file from scratch. XDP is Three-Dimensional XML file, and all the fields have to match the field names (case sensitive) and structure of the XFA source. You can try exporting the XDP using a submit button, and then reuse that empty XDP structure template file to inject in the field values from the database using whatever server-side language you choose. Output the filled XDP to the server buffer and Adobe Reader should automatically open it and populate the blank XFA PDF if everything matches up. This should work with Dynamic and Static XFA forms.
<?xml version="1.0" encoding="UTF-8"?>
<?xfa generator="XFA2_4" APIVersion="2.6.7120.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:data>
<topmostSubform>
<Pg1Header></Pg1Header>
<f1_1></f1_1>
<f1_2></f1_2>
<FederalClassification>
<f1_3></f1_3>
<f1_4></f1_4>
</FederalClassification>
<Exemptions>
<f1_5></f1_5>
<f1_6></f1_6>
</Exemptions>
<Address>
<f1_7></f1_7>
<f1_8></f1_8>
</Address>
<f1_9></f1_9>
<f1_10></f1_10>
<PartI></PartI>
<SSN>
<f1_11></f1_11>
<f1_12></f1_12>
<f1_13></f1_13>
</SSN>
<EmployerID>
<f1_14></f1_14>
<f1_15></f1_15>
</EmployerID>
<PartII></PartII>
<Col1></Col1>
<Col2></Col2>
<Page2>
<Pg2Header></Pg2Header>
<Col1></Col1>
<Col2></Col2>
</Page2>
<Pg3Header></Pg3Header>
<Col1>
<Table>
<HeaderRow></HeaderRow>
<BodyRow1></BodyRow1>
<BodyRow2></BodyRow2>
<BodyRow3></BodyRow3>
<BodyRow4></BodyRow4>
<BodyRow5></BodyRow5>
</Table>
</Col1>
<Col2></Col2>
<Pg4Header></Pg4Header>
<Col1>
<Table1>
<HeaderRow></HeaderRow>
<BodyRow1></BodyRow1>
<BodyRow2></BodyRow2>
<BodyRow3></BodyRow3>
<BodyRow4>
<BodyRow4Info></BodyRow4Info>
</BodyRow4>
<BodyRow5></BodyRow5>
<BodyRow6></BodyRow6>
</Table1>
<Table2>
<HeaderRow></HeaderRow>
<BodyRow1></BodyRow1>
<BodyRow2></BodyRow2>
<BodyRow3></BodyRow3>
<BodyRow4></BodyRow4>
<BodyRow5></BodyRow5>
<BodyRow6></BodyRow6>
<BodyRow7></BodyRow7>
<BodyRow8></BodyRow8>
</Table2>
</Col1>
<Col2></Col2>
<c1_1></c1_1>
<c1_7></c1_7>
</topmostSubform>
</xfa:data>
</xfa:datasets>
<pdf href="https://www.irs.gov/pub/irs-pdf/fw9.pdf" xmlns="http://ns.adobe.com/xdp/pdf/"/>
</xdp:xdp>
Copy link to clipboard
Copied
The main problem is finding out which field name corresponds with which actual field in the file, unless you have LCD and can open the file in edit mode...
Copy link to clipboard
Copied
Looks like LCD is USD$299, which is affordable. Any way to tell without purchasing LCD if this pdf file (https://www.irs.gov/pub/irs-pdf/fw9.pdf ) can be opened in edit mode?
Copy link to clipboard
Copied
Yes, it can.
Copy link to clipboard
Copied
Check out the following example:
fdftoolkit.net/examples/fw9demo.htm
Copy link to clipboard
Copied
You can fill the form in Acrobat and export the form data.
Copy link to clipboard
Copied
Sure, one way to prefill a PDF is to create a FDF file using FDFToolkit.net/iTextSharp. The FDF file can open in Adobe Reader and populate the fields. Another way is to "merge" the data with a blank PDF using FDFToolkit.net/iTextSharp.
FDFToolkit.net lets developers import data from EXCEL, MSAccess, MSSQL and any other ADO.net data source; or you can manually import each field value. FDFToolkit.net/iTextSharp (open-source) requires programming knowledge, and both libraries work with Visual Studio .NET (free).
Visit the following website for more information and examples:
fdftoolkit.net/examples/

