eureka2/acroforms

PDF form filling

1.0.6 2019-06-23 20:58 UTC

This package is auto-updated.

Last update: 2024-10-24 09:42:17 UTC


README

This library is a complete rewrite for php> = 7.1 of script93 developed by Olivier, with additional features:

  • Supports linearized PDF forms
  • Supports multi-pages PDF forms
  • Supports PDF 'radio', 'check box' and 'choice' fields in addition to 'text' fields
  • UTF-8 support

With this library, you can merge (inject) data into a PDF form (AcroForm), either from a PHP array, or from a FDF file.

Dependency

Installation

composer require eureka2/acroforms

Usage

  • With a PHP array:
<?php

require_once 'path/to/src/autoload.php';

use acroforms\AcroForm;

$fields = [
    'text' => [ // text fields 
        'text_field1'    => 'value of text_field1',
        'text_field2'    => 'value of text_field2',
        ......
    ],
    'button' => [ // button fields
        'radio1' => 'value of radio1',
        'checkbox1' => 'value of checkbox1',
        ........
    ]
];

$pdf = new AcroForm('exemple.pdf', [
    'pdftk' => '/absolute/path/to/pdftk'
]);
$pdf->load($fields)->merge();
if (php_sapi_name() == 'cli') {
	file_put_contents("filled.pdf", $pdf->output('S'));
} else {
	$pdf->output('I', 'filled.pdf');
}
?>
  • With a pre-filled FDF file:
<?php

require_once 'path/to/src/autoload.php';

use acroforms\AcroForm;

$pdf = new AcroForm('example.pdf', [
    'fdf' => 'example.fdf',
    'pdftk' => '/absolute/path/to/pdftk'
]);
$pdf->merge();
if (php_sapi_name() == 'cli') {
    $pdf->output('F', 'filled.pdf');
} else {
    $pdf->output('I', 'filled.pdf');
    // or $pdf->output('D', 'filled.pdf');
}
?>

Methods

Copyright and license

© 2019 Eureka2 - Jacques Archimède. Code released under the MIT license.