I have a php page that generates a pdf file by using fpdf. How to merge another pdf to the same page by using PDFMerge .
require('fpdf.php');
class PDF extends FPDF {
//some function here
}
some code here..
at the end
include 'PDFMerger.php';
$pdfMerge = new PDFMerger;
$pdf->addPDF('samplepdfs/one.pdf', 'all')
->merge('file', 'samplepdfs/TEST2.pdf');
$pdf->Output('filename.pdf', 'I');
when it executes I want to merge one.pdf
and filename.pdf
. How to get this? thanks in advance
You should use a native version of FPDI instead the PDFMerger class, because it uses a very old version of FPDI.
<?php
require_once('fpdf.php');
require_once('fpdi.php');
class PDF extends FPDI
{
// ...
}
$pdf = new PDF();
// ...
$pageCount = $pdf->setSoruceFile('samplepdfs/one.pdf');
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$tplId = $pdf->importPage($pageNo);
$pdf->AddPage();
$pdf->useTemplate($tplId, null, null, 0, 0, true);
}
$pdf->Output('filename.pdf', 'I');