Im using a library called PDFmerger , naturally, it merges pdfs together. I wish to run a cron every night that builds these to have them ready for the next day. The issue is when I run the code after the first one it fails because it is attempting to redeclare the class.
The for
statement...
foreach ($pdfs_to_build as $pdf) {
// do stuff
$this->merge_pdfs($pdf['pdf_id']);
}
And my pdf merging code that gets ran in the loop...
$pdf = new PDFMerger;
$pdf->addPDF(DIR_BOOKS.$book_path.'/static-pages/page-1.pdf', '1');
$pdf->addPDF(DIR_FINAL_PDFS.$pdf_id.'/custom-page-1.pdf','1');
$pdf->addPDF(DIR_BOOKS.$book_path.'/static-pages/page-2.pdf', '1');
$pdf->merge('file', DIR_FINAL_PDFS.$pdf_id.'/final-build-'.$pdf_id.'.pdf');
Error after the first 1 is complete and we've onto the next one...
Fatal error: Cannot redeclare class PDFMerger in /var/www/example/pdfmerger/PDFMerger.php on line 24
Im wondering is there a workaround for this?