函數(shù)名:fdf_add_template()
適用版本:PHP 4 >= 4.3.0, PHP 5, PHP 7
用法:fdf_add_template(resource $fdf_document, int $newpage, string $filename, string $template, int $rename)
描述:將一個(gè)PDF模板添加到一個(gè)fdf文檔中的指定頁(yè)面。
參數(shù):
- $fdf_document:fdf文檔的資源句柄。
- $newpage:要添加模板的頁(yè)面編號(hào)。第一頁(yè)的編號(hào)為1。
- $filename:PDF模板文件的路徑。
- $template:模板的名稱。
- $rename:指定是否重命名模板字段。
返回值:成功時(shí)返回 TRUE,失敗時(shí)返回 FALSE。
示例:
// 創(chuàng)建一個(gè)新的fdf文檔
$fdf = fdf_create();
// 打開(kāi)一個(gè)現(xiàn)有的PDF模板
$templatePath = 'path/to/template.pdf';
$templateName = 'MyTemplate';
$templatePage = 1;
// 添加模板到fdf文檔
if (fdf_add_template($fdf, $templatePage, $templatePath, $templateName, 1)) {
echo "模板添加成功!";
} else {
echo "模板添加失??!";
}
// 保存fdf文檔到文件
$fdfPath = 'path/to/output.fdf';
if (fdf_save($fdf, $fdfPath)) {
echo "fdf文檔保存成功!";
} else {
echo "fdf文檔保存失??!";
}
// 關(guān)閉fdf文檔資源
fdf_close($fdf);
注意事項(xiàng):
- 該函數(shù)需要 FDF 函數(shù)庫(kù)的支持。在編譯 PHP 時(shí)需要啟用 --with-fdf 配置選項(xiàng)。
- 添加模板之前,需要先創(chuàng)建一個(gè)空的fdf文檔資源句柄,可以使用 fdf_create() 函數(shù)來(lái)創(chuàng)建。
- 模板文件必須是一個(gè)有效的PDF文件。