This project demonstrates using the FDF Toolkit for Java to extract form fields and values from a PDF form.
It assumes the PDF has been created using Adobe tools to create a PDF form. See:
Creating and distributing PDF forms in Adobe Acrobat
This project uses two tools in sequence:
- PDFtk Server to get an FDF file from a PDF
- FDF Toolkit for Java to get form fields and values from an FDF file
We will use the PDFtk Server to generate an FDF file from the PDF.
The PDFtk Server is part of PDFtk - The PDF Toolkit from PDF Labs run by Sid Steward, who is also the author of PDF Hacks (O’Reilly).
PDFLabs provides PDFtk Server installers for Windows, macOS, Red Hat Enterprise Linux and CentOS.
You can compile PDFtk Server from its source code.
Many Linux distributions provide a PDFtk package you can download and install using their package manager.
The installer for macOS from PDFtk Server does not produce any output for many commands.
The workaround is to download the latest version - not listed on the official website.
Thanks to PDFtk Server Install Workaround for Mac OS X and stackoverflow pdftk-hanging-on-macos-sierra.
The format of the command to generate FDF from a PDF is:
pdftk INPUTACROFORM.pdf generate_fdf output EXTRACTEDFDF.fdf
For example:
pdftk SecuritySearchForm.pdf generate_fdf output extract.fdf
pdftk SecuritySearchFormSubmitted.pdf generate_fdf output extractSubmitted.fdf
PDFtk features are fully documented on its man page. There are also some command-line examples.
Consult PDFLabs for PDFtk Server Commercial Support and PDFtk Server Redistribution License terms.
We will use the Acrobat Forms Data Format (FDF) Toolkit.
This project contains the FDF Toolkit for Java downloaded from FDF Toolkit for Java (ZIP: 2.2MB).
Include [jFdfTk.jar](FDF Toolkit for Java/Headers and Libraries/Java/jFdfTk.jar) in the Classpath.
Note: The terms as stated in the FDF Toolkit End User License Agreement.
Compile and run ExtractFields.main() from src/ExtractFields.java.
Output:
fieldName: NAME fieldValue: VALUE
...
Note: By downloading these files, you agree to the terms as stated in the End-User License Agreement included below.
FDF Toolkit End User License Agreement (PDF, 48k)
FDF Toolkit for Windows (ZIP: 2.2MB)
FDF Toolkit for Java (ZIP: 2.2MB)
FDF Toolkit for Unix (ZIP: 2.9MB)
iText 7 Community, an open source PDF engine to create your smart document workflow.
API documentation for creating PDF solutions | iText Developers
http://itextsupport.com/apidocs/itext7/latest/com/itextpdf/forms/PdfAcroForm.html