简体   繁体   中英

FPDF: Mergin 2 PDF files into 1 PDF with 1 page

I'm trying to merge 2 PDFs into 1 PDF with only one page. Every PDF has 1 page.

Thanks to this post http://www.setasign.com/products/fpdi/about/ I was able to make the first PDF the template. Only Problem now is how do I import the other and set it as content without getting a PDF with multiple pages as result.

I hope somebody can help.

Thanks in advance.

An imported page doesn't mean that it results in a new page in your document until you write the code for this behaviour. Taking the example on the linked page you can import another documents page this way:

<?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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM