I have some PHP pages and PDF that I need to merge into a single PDF file. I am using the MPDF library but I am getting the following error:
"Unable to find object (4, 0) at expected location."
This is my code:
<?php
function pdf_recreate($f)
{
rename($f, str_replace('.pdf', '_.pdf', $f));
$fileArray = [str_replace('.pdf', '.pdf', $f)];
$outputName = $f;
$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outputName ";
foreach ($fileArray as $file) {
$cmd .= $file . " ";
}
$result = shell_exec($cmd);
//unlink(str_replace('.pdf','_.pdf',$f));
}
$new_pdf_recreate = pdf_recreate('../upload_dir/testPDF.pdf');
try {
$mpdf = new \Mpdf\Mpdf();
$mpdf->setFooter('{PAGENO}');
$mpdf->SetImportUse();
// Create Initial Invoice PDF
$mpdf->WriteHTML($content);
// import C.pdf
// $pagecount = $mpdf->SetSourceFile(dirname(__FILE__).'/C.pdf');
$pagecount = $mpdf->SetSourceFile(dirname(__FILE__) . $new_pdf_recreate);
//Loop through the pages adding them to the PDF
for ($i = 1; $i <= $pagecount; $i++) {
$mpdf->AddPage('');
$import_page = $mpdf->ImportPage($i);
$mpdf->UseTemplate($import_page);
}
$mpdf->Output();
} catch (\Mpdf\MpdfException $e) {
echo $e->getMessage();
}
Can anyone tell me why am getting this message/error?