12

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

Rax Shah
  • 531
  • 5
  • 18
  • are you using dedicated hosting or shared hosting?.. if you have linux based dedicated hosting then have alternate solution for this. – Haresh Vidja Aug 09 '16 at 05:42
  • I have working on localhost – Rax Shah Aug 09 '16 at 05:43
  • but what about your server configuration? finally you upload code in server right? – Haresh Vidja Aug 09 '16 at 05:43
  • no now i'm working on localhost after in localhost done i will upload on server. i'm face problem in localhost. im using php 5.6 version. – Rax Shah Aug 09 '16 at 05:46
  • I can give solution if your server will be dedicated and linux based.. my solution will work on localhost for sure, but in server we have to install some software for this so must have dedicated server, – Haresh Vidja Aug 09 '16 at 05:48

3 Answers3

3

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.

Joel Hernandez
  • 2,195
  • 1
  • 13
  • 17
2

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');
0

I have done to merge pdf greater then version 1.5 using mpdf and shell script.

$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);


$tmp_dir1='upload_files/tmp_ao_pdf';
if(!is_dir($tmp_dir1))
{
  mkdir($tmp_dir1,0777);
}            
$file_path=$tmp_dir1."/"."generate_html.pdf";
$mpdf->Output($file_path,'F');

$attachh_pdf_name="upload_files/order_form_instructions_energy_supply.pdf";
$fileArray= array($file_path,$attachh_pdf_name);
$datadir = "upload_files/";
$outputName = $datadir."orderform_".$order_id.".pdf";
$cmd = "gs -q -dNOPAUSE -dBATCH -dAutoRotatePages=1 -sPAPERSIZE=legal -sDEVICE=pdfwrite -sOutputFile=$outputName ";
foreach($fileArray as $file) {
    $cmd .= $file." ";
}
$result = shell_exec($cmd);
barbsan
  • 3,418
  • 11
  • 21
  • 28
Rax Shah
  • 531
  • 5
  • 18