FPDF:将2个PDF文件合并为1页PDF

时间:2015-02-26 13:55:07

标签: php pdf fpdf fpdi

我试图将2个PDF合并为只有一页的1个PDF。每个PDF都有1页。

感谢这篇文章 http://www.setasign.com/products/fpdi/about/ 我能够将第一个PDF作为模板。现在唯一的问题是如何导入另一个并将其设置为内容而不会得到包含多个页面的PDF。

我希望有人可以提供帮助。

提前致谢。

1 个答案:

答案 0 :(得分:3)

导入的页面并不意味着它会在您编写此行为的代码之前在文档中生成新页面。以链接页面为例,您可以通过以下方式导入其他文档页面:

<?php
require_once('fpdf.php');
require_once('fpdi.php');

$pdf = new FPDI();

$pdf->setSourceFile("Fantastic-Speaker.pdf");
$tplIdxA = $pdf->importPage(1, '/MediaBox');

$pdf->setSourceFile("Another-Fantastic-Speaker.pdf");
$tplIdxB = $pdf->importPage(1, '/MediaBox');

$pdf->addPage();
// place the imported page of the first document:
$pdf->useTemplate($tplIdxA, 10, 10, 90);
// place the imported page of the snd document:
$pdf->useTemplate($tplIdxB, 100, 10, 90);

$pdf->Output();
相关问题