我尝试将使用mPDF插件的pdf与最新版本合并,但是 错误来了 使用pdf版本1.3但未完成1.5
的PDF合并工作我试过下面的代码
<?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');
?>
我收到此错误
mPDF error: Unable to find xref table - Maybe a Problem with auto_detect_line_endings
提前致谢
答案 0 :(得分:2)
RAX: 你尝试过不同的pdf文件吗?这可能对您有所帮助: http://www.vankouteren.eu/blog/2009/07/fpdf-error-unable-to-find-xref-table/
其中一个应该合并的PDF最初是从中创建的 PDF创建者将其签名放在属性中的Word PDF文件。删除此签名后(在这种情况下打开 使用Adobe Illustrator的PDF并再次保存它)问题是 解决。
答案 1 :(得分:1)
您以前可以使用 Ghostscript 实用工具
将输入的PDF文件版本降级。gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-o order_form_instructions_energy_supply_v1.4.pdf \
order_form_instructions_energy_supply.pdf
,然后在mPDF lib中使用降级的文件
您的脚本:
<?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');
答案 2 :(得分: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);