php 通过使用 TCPDF 合并 PDF 文档来创建新的 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1630016/
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
Creating a new PDF by Merging PDF documents using TCPDF
提问by LuRsT
How can I create a new document using other PDFs that I'm generating?
如何使用我生成的其他 PDF 创建新文档?
I have methods to create some documents, and I want to merge them all in a big PDF, how can I do that with TCPDF?
我有创建一些文档的方法,我想将它们全部合并到一个大的 PDF 中,我该如何使用 TCPDF 做到这一点?
I do not want to use other libs.
我不想使用其他库。
回答by Sygmoral
TCPDF has a tcpdf_importclass, added in 2011, but it is still "under development". If you don't want to use anything outside of TCPDF, you're out of luck!
TCPDF 有一个tcpdf_import类,是在 2011 年添加的,但它仍在“开发中”。如果你不想使用 TCPDF 之外的任何东西,那你就走运了!
But FPDIis an excellent additionto TCPDF: it's like an addon. It's as simple as this:
但是FPDI是对 TCPDF 的一个很好的补充:它就像一个插件。就这么简单:
require_once('tcpdf/tcpdf.php');
require_once('fpdi/fpdi.php'); // the addon
// FPDI extends the TCPDF class, so you keep all TCPDF functionality
$pdf = new FPDI();
$pdf->setSourceFile("document.pdf"); // must be pdf version 1.4 or below
// FPDI's importPage returns an object that you can insert with TCPDF's useTemplate
$pdf->useTemplate($pdf->importPage(1));
Done!
完毕!
See also this question: TCPDF and FPDI with multiple pages
回答by Phuc
Why don't you use Zend_PDF, it 's really a very good way to merge file.
为什么不使用 Zend_PDF ,它确实是一个非常好的合并文件的方法。
<?php
require_once 'Zend/Pdf.php';
$pdf1 = Zend_Pdf::load("1.pdf");
$pdf2 = Zend_Pdf::load("2.pdf");
foreach ($pdf2->pages as $page){
$pdf1->pages[] = $page;
}
$pdf1->save('3.pdf');
?>
回答by opHASnoNAME
Hi i think TCPDF is not able to merge pdf files.
嗨,我认为 TCPDF 无法合并 pdf 文件。
You can try it with an shell command and
你可以用一个 shell 命令来试试,然后
So you dont have to use an other pdf library.
因此,您不必使用其他 pdf 库。
回答by Darryl Hein
Check out FPDI and FPDF_TPL. This isn't a perfect solution, but you can basically use FPDF_TPL to create a template of your PDF file and the insert it into your PDF file.
查看FPDI 和 FPDF_TPL。这不是一个完美的解决方案,但您基本上可以使用 FPDF_TPL 创建 PDF 文件的模板并将其插入到您的 PDF 文件中。

