Package: pdfforms
pdfforms is a small utility for populating fillable pdf forms from a spreadsheet
data source.  It was created with the intent of filling US tax forms using
tax data prepared with a spreadsheet, but should be equally applicable to
other forms.FeaturesAssigns numeric id for each fieldGenerates test pdf showing ids of text fieldsMerges spreadsheet data into final filled pdfWorks with multiple spreadsheet formatsCan process multiple pdfs at a timeCan be used as a library or CLIOptional rounding and number formattingRequirementspdfforms requires Python 3.5 or higher,pyexcelfor data loading, andpdftk, which does all the real work.InstallationTo install:pip install pdfformsDocumentationFor complete documentation, seehttps://pdfforms.readthedocs.io/ExampleLet’s say you have a spreadsheet with your tax calculations.  You want to
populate your tax forms with the data from the spreadsheet.  pdfforms
allows you to do so with the following steps:First pdfforms must inspect the forms to be filled.  pdfforms will
extract a list of fields in each of the specified documents.  Each field
is assigned a numeric id, and test documents are generated with filled
forms, showing the id of each text field:$ pdfforms inspect f1040*.pdf
f1040sse.pdf
f1040sce.pdf
f1040.pdfThe filled test pdfs are stored by default in thetest/subdirectory.Browse the test pdf files and add the field numbers of the fields you
need to fill to your spreadsheet.  pdfforms only reads the first and
third columns of the datafile.  The first column should contain the name
of the pdf file with the form to fill and the field numbers.  The third
column should contain the data to be written into the field.  The rest
of the sheet is ignored, so you can use it for notes, calculations, etc.pdfforms is case sensitive!  The file name in the spreadsheet must match
exactly the name of the pdf to be filled.Below is an example spreadsheet for a (fictional) 2016
tax return.f1040.pdfForm 104020163First Name and initialJohn Q4Last NamePublic5SSN321546789321-54-67896Spouse’s NameSusie7Spouse’s Last NamePublic8SSN132458697132-45-86979Address5776 Winding Ln11Springfield, MA18Filing statusMJ24Exemption - self125Exemption - spouse127Dependent nameTimothy Public28Dependent ssn531248680531-24-868029Dependent relationshipSon30Dependent under 17131Dependent nameAbigail Public32Dependent ssn428775031428-77-503133Dependent relationshipDaughter34Dependent under 17145Line 6a246Line 6c249Line 6d450Line 760,000salaries52Line 8a124taxable interest64Line 1215,000business income92Line 2275,124total income102Line 271,060half SE tax121Line 361,060123Line 3774,064Adjusted Gross Income125Line 3874,064133Line 4012,600Standard Deduction135Line 4161,464137Line 4216,200Exemptions$ 4,050139Line 4345,264Taxable income145Line 444,528Tax151Line 474,528161Line 522,000Child Tax Credit171Line 552,000Total Credits173Line 562,528175Line 572,119Self-employment tax196Line 634,647Total Tax198Line 648,688Tax withheld225Line 748,688Total Payments227Line 754,041Amount you overpaid230Line 76a4,041Amount you want refunded232Line 76b123654789Routing Number234Line 76cSavingsAccount Type235Line 76d135724Account Number247OccupationSalesman248Daytime phone number413-555-1212249Spouse’s OccupationArtistf1040sce.pdfSchedule C-EZ0NameSusie Public1SSN132-45-86979Line F2No2Line AArtistPrinciple business or profession3Line B711510Business Code13Line 122,000gross receipts15Line 27,000total expenses17Line 315,000net profitf1040sse.pdfForm SE - Section A Short Schedule SE0NameSusie Public1SSN132-45-86976Line 215,0008Line 315,00092.35%10Line 413,85315.30%12Line 52,11950.00%14Line 61,060The test pdfs do not show field numbers for checkboxes.  Currently the
only way to fill checkboxes is to examine thefields.jsonfile and
find the field number and allowed values of the checkbox.Once the file name and field numbers have been added to your spreadsheet,
save the spreadsheet as a csv file and fill the forms:$ pdfforms fill mydata.csv
f1040sse.pdf
f1040sce.pdf
f1040.pdfThe final, populated pdf files are saved by default to thefilled/subdirectory.Changelog2.0.0date:15 Aug, 2021Use pyexcel to load spreadsheet data, supports xlsx, ods, csv, and moreAdd options to round values, add thousands separatorsSplit codebase up and publish an APIMake .pdf suffix recognition case-insensitiveBetter handling of invalid inputExpanded documentationGeneral code clean-up, refactoring, linting, and reformatting1.2.1date:3 July, 2020Don’t crash when subcommand not supplied (Thanks @PiDelport for the PR)1.2.0date:24 September, 2019Added--no-flattenoption to keep form fillableinspectdoesn’t crash if passed a pdf without fillable form1.1.0date:4 July, 2018Fixed handling of whitespace (Thanks @rohitkhirapate for the bug report)Added python 3.4 compatibility (Thanks @oneyb for the PR)1.0.0date:1 May, 2017Initial release