Form Filler
FormFiller reads and fills AcroForm fields using incremental updates, preserving the original PDF structure and any existing signatures.
Opening a PDF
Section titled “Opening a PDF”use Phpdftk\Pdf\Toolkit\FormFiller;
// From file$filler = FormFiller::open('form.pdf');
// From string$filler = FormFiller::openString($pdfBytes);
// Encrypted PDF$filler = FormFiller::open('secured.pdf', password: 'secret');Reading field information
Section titled “Reading field information”List all fields
Section titled “List all fields”$names = $filler->getFieldNames();// => ['name', 'email', 'subscribe', 'country']Get field details
Section titled “Get field details”$info = $filler->getFieldInfo('email');
$info->name; // 'email'$info->type; // FieldType::Text$info->value; // current value or null$info->flags; // int (PDF /Ff flags)$info->maxLen; // ?int (max length for text fields)$info->options; // ?string[] (options for choice fields)$info->rect; // ?float[] ([x1, y1, x2, y2] widget rectangle)Get all current values
Section titled “Get all current values”$values = $filler->getFieldValues();// => ['name' => 'Jane', 'email' => null, 'subscribe' => 'Off', ...]Check field existence
Section titled “Check field existence”if ($filler->hasField('signature')) { // field exists}Filling fields
Section titled “Filling fields”Text fields
Section titled “Text fields”$filler->fill('name', 'Jane Doe') ->fill('email', 'jane@example.com');Fill multiple fields at once
Section titled “Fill multiple fields at once”$filler->fillMany([ 'name' => 'Jane Doe', 'email' => 'jane@example.com', 'city' => 'Toronto',]);Checkboxes
Section titled “Checkboxes”$filler->check('subscribe'); // check$filler->check('subscribe', false); // uncheckChoice fields (dropdowns, list boxes)
Section titled “Choice fields (dropdowns, list boxes)”$filler->select('country', 'Canada');Saving
Section titled “Saving”// To file$filler->save('filled.pdf');
// To string$bytes = $filler->toBytes();Field types
Section titled “Field types”The FieldType enum covers the four PDF interactive field types:
| Enum case | PDF value | Covers |
|---|---|---|
FieldType::Text | Tx | Text input fields |
FieldType::Button | Btn | Checkboxes, radio buttons, push buttons |
FieldType::Choice | Ch | Dropdowns, list boxes |
FieldType::Signature | Sig | Signature fields |
Document info
Section titled “Document info”$filler->getPageCount(); // intEscape hatch
Section titled “Escape hatch”$reader = $filler->getReader(); // PdfReader