Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF not merge greater than PDF-1.5 version using mPDF

Tags:

php

mpdf

I try to merge pdf using mPDF plugin with latest version but the error coming PDF merging working when using pdf version 1.3 but not done for 1.5

I have try below code

<?php
$mihir='<html>
<body>
  Generate PDFs with merge
</body>
</html>';    

require_once("MPDF/mpdf.php");
$mpdf=new mPDF(); 
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; 
$mpdf->WriteHTML($mihir);

$mpdf->AddPage();
$mpdf->SetImportUse();
$pagecount = $mpdf->SetSourceFile("order_form_instructions_energy_supply.pdf");
$tplId = $mpdf->ImportPage($pagecount);
$mpdf->UseTemplate($tplId);
$mpdf->Output('test.pdf','D');
?>

I'm getting this error

mPDF error: Unable to find xref table - Maybe a Problem with auto_detect_line_endings

thanks in advance

like image 899
Rax Shah Avatar asked Aug 04 '16 09:08

Rax Shah


Video Answer


2 Answers

Rax: Have you tried with different pdf documents? This may help you: http://www.vankouteren.eu/blog/2009/07/fpdf-error-unable-to-find-xref-table/

One of the PDFs which should be merged was originally created from Word by a PDF creator which placed its signature in the properties of the PDF document. After removing this signature (in this case opening the PDF with Adobe Illustrator and saving it again) the problem was solved.

like image 77
Joel Hernandez Avatar answered Sep 21 '22 19:09

Joel Hernandez


You can previously downgrade input PDF file version with Ghostscript utility

gs \
  -sDEVICE=pdfwrite \
  -dCompatibilityLevel=1.4 \
  -o order_form_instructions_energy_supply_v1.4.pdf \
     order_form_instructions_energy_supply.pdf

and then use downgraded file in mPDF lib

Your script:

<?php
$mihir='<html>
<body>
Generate PDFs with merge
</body>
</html>';    

require_once("MPDF/mpdf.php");
$mpdf=new mPDF(); 
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; 
$mpdf->WriteHTML($mihir);

$mpdf->AddPage();
$mpdf->SetImportUse();

$cmd = 'gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -o order_form_instructions_energy_supply_v1.4.pdf order_form_instructions_energy_supply.pdf';
shell_exec($command);

$pagecount = $mpdf->SetSourceFile('order_form_instructions_energy_supply_v1.4.pdf');
$tplId = $mpdf->ImportPage($pagecount);
$mpdf->UseTemplate($tplId);
$mpdf->Output('test.pdf','D');
like image 35
Evgeny Levchenko Avatar answered Sep 21 '22 19:09

Evgeny Levchenko