PHP PDF Mapping: Efficient Data Entry in Fillable PDFs

Shiv Kumar
2 min readJan 28, 2024

--

As of my knowledge , there are several PHP libraries and packages available for working with PDFs, including functionalities related to mapping and handling fillable fields. Keep in mind that the availability of packages can change over time, and new ones may be developed while others become outdated.

Some popular PHP libraries for working with PDFs and fillable fields include:

  1. TCPDF: A widely used PHP library for creating PDF documents. It provides support for form fields and interactive elements.
  2. FPDF: Another popular PHP library for creating PDFs. While it doesn’t directly support interactive forms, you can manually add form fields.
  3. mPDF: A PHP library that allows you to generate PDF files with support for various features, including form fields.
  4. Setasign/FPDF & Setasign/FPDI: These libraries allow you to import existing PDFs into FPDF and work with form fields.
  5. pdftk-php: A PHP wrapper for the PDFtk command-line tool, which can be used to fill PDF forms.

let explore about pdftk-php -

PDFtk is a cross-platform tool that allows users to manipulate PDF documents, including merging, splitting, and filling out PDF forms

Install the pdftk-php library using a package manager like Composer.

composer require mikehaertl/php-pdftk

  • Once installed, you can use the pdftk-php library in your PHP scripts.

// Include the composer autoloader
require ‘vendor/autoload.php’;

use mikehaertl\pdftk\Pdf;

// Create a Pdf object
$pdf = new Pdf(‘input.pdf’);

// Fill form fields (if the PDF has form fields)
$pdf->fillForm([
‘name’ => ‘John Doe’,
‘email’ => ‘joh.doe@example.com’,
]);

// Save the output to a new PDF file
$pdf->saveAs(‘output.pdf’);

Some usefull command :-

Getting Information about PDF:

pdftk input.pdf dump_data output info.txt

Splitting PDFs:

pdftk input.pdf cat 1–3 output split.pdf

Merging PDFs:

pdftk file1.pdf file2.pdf cat output merged.pdf

--

--

Shiv Kumar

Software Engineer | Web Developer | Writer | Symfony | Spryker | Redis | Elastic Search | Rabbit MQ |Jenkin