When I am trying to upload a pdf file and separating each page as pdf, with some pdf files it is working but some of pdf files show this error:
mPDF error: Unable to find xref table -" Maybe a Problem with auto_detect_line_endings"
My code:
ini_set('memory_limit', '512M');
$pagecount = Model::count_pages($documentPath.$journalDoc);
for ($i=1; $i<=$pagecount; $i++) {
$pdf = new mPDF('','Letter',12,'helvetica, sans-serif',200,0,0,20,0,10,'P');
$pdf->SetImportUse();
$pdf->SetSourceFile($documentPath.$journalDoc);
$import_page = $pdf->ImportPage($i);
$pdf->UseTemplate($import_page);
$pdf->Output($output_dir.$i.'.pdf', 'F');
}
The version of FPDI in the offical repo of mPDF is very old. You may try to update to the latest version. Or you simply use the official version of FPDI which uses FPDF.
If you get a message about "unssported compression" you may check out the FPDI PDF-Parser add-on. Notice that there's a license incompatibility to mPDF.
This can be caused by the PDF file version that is incompatible with mPDF. You would better regress the PDF file version.
If you extracted a page from a file, you may have used an Adobe software. Just use pdftk or pdfchain on Linux platform to solve the problem.
This can be caused by PDF files of a version incompatible with the mPDF you're running. You can often circumvent the problem by regressing the source PDF files.
For instance, for mPDF v6.0 try brining your PDFs down to at most v1.4 using something like Ghostscript. (Where old.pdf is you're sourcefile)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o new.pdf old.pdf
Ghostscript won't write to the file it's reading so if you're doing this inline you'll have to dance;
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o new.pdf old.pdf; mv -f new.pdf old.pdf