PDF files are one of the most common ways of sharing documents online. Whether we need to pass our clients’ documents to third-party service providers like banks or insurance companies, or just to send a CV to an employer, using a PDF document is frequently the first option.
PDF files can transfer plain/formatted text, images, hyperlinks, and even fillable forms. In this tutorial, we’re going to see how we can fill out PDF forms using PHP and a great PDF manipulation tool called PDFtk Server.
To keep things simple enough, we’ll refer to
PDFtk Server as
PDFtk throughout the rest of the article.
We’ll use Homestead Improved for our development environment, as usual.
Once the VM is booted up, and we’ve managed to ssh into the system with
vagrant ssh, we can start installing
sudo apt-get install pdftk
To check if it works, we can run the following command:
The output should be similar to:
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit:www.pdftk.com. This is free software; see the source code for copying conditions. There is NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
PDFtk provides a wide variety of features for manipulating PDF documents, from merging and splitting pages to filling out PDF forms, or even applying watermarks. This article focuses on using PDFtk to fill out a standard PDF form using PHP.
PDFtk uses FDF files for manipulating PDF forms, but what is an FDF file?
FDF or Form Data File is a plain-text file, which can store form data in a much simpler structure than PDF files.
Simply put, we need to generate an FDF file from user submitted data, and merge it with the original PDF file using PDFtk’s commands.
The structure of an FDF file is composed of three parts: the header, the content and the footer:
Copy and paste this URL into your WordPress site to embed
Copy and paste this code into your site to embed