eureka2 / acroforms
PDF form filling
Installs: 4 072
Dependents: 1
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.1.3
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.