php tcpdf - 从现有的 PDF 文档开始

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1418945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:29:57  来源:igfitidea点击:

tcpdf - start with existing PDF document

phppdftcpdf

提问by Marko

I have several PDF templates that I would like to load and modify and output using tcpdf.

我有几个 PDF 模板,我想使用 tcpdf 加载、修改和输出这些模板。

Is it possible to load an existing PDF and use it as a starting point in tcpdf?

是否可以加载现有的 PDF 并将其用作 tcpdf 的起点?

回答by timdev

You want to use FPDI.

您想使用FPDI

There's some example code here.

这里也有一些示例代码在这里

回答by AbdulkadirFaghi

I have tried the free version of FPDI but does not support PDF version 1.5 or higher.

我尝试过 FPDI 的免费版本,但不支持 PDF 1.5 或更高版本。

If someone else is looking for a free solution I have used TCPDI. You can find it on github https://github.com/pauln/tcpdiIf you are using composer, you can find some fork for composer too. Just search tcpdi on github.

如果其他人正在寻找免费的解决方案,我已经使用了 TCPDI。你可以在 github https://github.com/pauln/tcpdi上找到它 如果你使用的是 composer,你也可以找到一些 composer 的 fork。只需在 github 上搜索 tcpdi。

Once you add it to your project, the code is quite simple. It is an extension of TCPDF so all your previous code keep working

一旦你将它添加到你的项目中,代码就非常简单了。它是 TCPDF 的扩展,因此您以前的所有代码都可以继续工作

This is a snippet from my code. I used it to save a copy of the privacy policy (a static pdf) with the user name and agreement date on each page footer.

这是我的代码片段。我用它来保存隐私政策的副本(静态 pdf),在每个页脚上都有用户名和协议日期。

// Create new PDF document
$pdf = new TCPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
...
// Add the pages from the source file.
$pagecount = $pdf->setSourceFile($policyPdfPath);
for ($i = 1; $i <= $pagecount; $i++) {
    $tplidx = $pdf->importPage($i);
    $pdf->AddPage();
    $pdf->useTemplate($tplidx);
    // Add agreement text in document footer
    $pdf->SetXY(15,282);
    $pdf->Cell(180, 5, "Documento approvato da {$fullName} il {$date}", 0, 0, 'C');
}
// Send PDF on output
$pdf->Output(FOLDER_PATH . DIRECTORY_SEPARATOR . "{$userId}.pdf", 'F');