Pdftk
Using pdftk is a powerful way to produce PDF files. This command line application is lightweight and fast. It can be used for many things such as combining multiple PDF files, splitting pages into new documents, encryption, and attaching files.
How it Works
Using an FDF file created in the previous article, save this to the web server instead of outputing it to the client. Then run the command line application providing the PDF form and the FDF file and flatten into a single output PDF.
Advantages
- The unfilled PDF file does not have to be web accessible
- The filled PDF form is provided to the client
- Free
- All programs support reading the resulting PDF files
Disadvantages
- Not always easy to work with
- May not be compatible with all PDF files (version 1.6 forms not working at the time of this post)
- A C++ executable needs to be placed on the web server
- The PDF form must be created in a way that has named fields
Implementation
Create a FDF file from the previous article and save it to the web server. Have the PHP application run the following shell command on the web server (assuming pdftk can be run without a full path):
pdftk pdfform.pdf fill_form fdffile.fdf output outputpdf.pdf flatten
—
Pdftk can be obtained here: