SetaPDF Demos PHP libraries to handle, modify or create PDF files

Fill All Field Types

This demo shows you how to fill in all field types depending on their class instances.

PHP
<?php

use setasign\SetaPDF2\Core\Document;
use setasign\SetaPDF2\Core\Writer\HttpWriter;
use setasign\SetaPDF2\FormFiller\Field\AbstractField;
use setasign\SetaPDF2\FormFiller\FormFiller;

// load and register the autoload function
require_once __DIR__ . '/../../../../../bootstrap.php';

$files = [
    require 'data/dataset-1.php',
    require 'data/dataset-2.php',
    require 'data/dataset-3.php',
];

$dataId = displaySelect('Select file:', $files, true, 'displayValue');
$data = $files[$dataId];

$document = Document::loadByFilename(
    $data['file'],
    new HttpWriter('filled.pdf', true)
);

$formFiller = new FormFiller($document);
$fields = $formFiller->getFields();

/** @var AbstractField $field */
foreach ($fields as $field) {
    $fieldName = $field->getQualifiedName();
    if (!isset($data['values'][$fieldName])) {
        continue;
    }

    $field->setValue($data['values'][$fieldName]);
}

$document->save()->finish();
PHP
<?php

return [
    'displayValue' => 'lenstown/Order-Form-without-Signaturefield.pdf',
    'file' => $assetsDirectory . '/pdfs/lenstown/Order-Form-without-Signaturefield.pdf',
    'values' => [
        'Order Number' => '987654',
        'Date' => date('Y-m-d'),
        'Name' => 'Test Person',
        'Company Name' => 'Awesome Company',
        'Adress' => 'Examplestreet 1',
        'City' => 'Exampleria',
        'Zip Code' => '12345',
        'State' => '-',
        'Country' => 'Orasiania',
        'Phone' => '+12 3456 7890',

        'Name_2' => 'Another Test Person',
        'Company Name_2' => 'A more Awesome Company',
        'Adress_2' => 'Examplestreet 2',
        'City_2' => 'Exampleria',
        'Zip Code_2' => '12345',
        'State_2' => '-',
        'Country_2' => 'Orasiania',
        'Phone_2' => '+12 7890 3456',

        'Item-Number.0' => 'X1245',
        'Description.0' => 'Rotator',
        'Quantity.0' => '10',
        'Unit-Price.0' => '15.00 €',
        'Amount.0' => '150.00 €',

        'Item-Number.1' => 'X4567',
        'Description.1' => 'Migrator',
        'Quantity.1' => '5',
        'Unit-Price.1' => '25.00 €',
        'Amount.1' => '125.00 €',

        'Subtotal' => '275.00 €',
        'Tax' => '52.25 €',
        'Freight Cost' => '10.00 €',
        'Total Amount' => '337.25 €'
    ]
];
PHP
<?php

return [
    'displayValue' => 'forms/Sunnysunday-Example.pdf',
    'file' => $assetsDirectory . '/pdfs/forms/Sunnysunday-Example.pdf',
    'values' => [
        'Balloons' => 'Yes',
        'How many balloons' => '10',
        'Balloon color' => ['red', 'green'],
        'Favorite Cake' => "Apple Cake with cream.\nOr something with fancy chocolate!",
        'Pets' => 'Yes',
        'Pet kind' => 'Dog',
        'Pet name' => 'Alec',
        'Arrival' => '3pm',
        'Departure' => '9pm',
    ]
];
PHP
<?php

return [
    'displayValue' => 'forms/Customizer-Example.pdf',
    'file' => $assetsDirectory . '/pdfs/forms/Customizer-Example.pdf',
    'values' => [
        'Core-Power' => '2 x 3 Ghz',
        'RAM' => '8192',
        'Graphics Device 1' => 'EAN67834654',
        'Graphics Device 2' => 3,
        'Harddisk 1' => 'SSD 10000GB', // the combo box is editable
        'Harddisk 2' => '1000GB',
        'Harddisk 3' => '750GB',
        'WLAN' => true,
        'Bluetooth' => true,
        'Card Reader' => true,
        'Feedback' => "It should be silent!\nAnd it should look fancy and modern!",
    ]
];