eureka2/acroforms

1.0.6 2019-06-23 20:58 UTC

This package is auto-updated.

Last update: 2024-09-24 09:25:57 UTC


README

这个库是对Olivier开发的script93的完整重写,针对php≥7.1,并增加了额外功能。

  • 支持线性化PDF表单
  • 支持多页PDF表单
  • 除了“文本”字段外,还支持PDF的“单选框”、“复选框”和“选择”字段
  • 支持UTF-8

使用这个库,您可以将数据合并(注入)到PDF表单(AcroForm)中,无论是从PHP数组还是从FDF文件中。

依赖项

安装

composer require eureka2/acroforms

用法

  • 使用PHP数组
<?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');
}
?>
  • 使用预填充的FDF文件
<?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');
}
?>

方法

版权和许可

© 2019 Eureka2 - Jacques Archimède. 代码在MIT许可下发布。