如何通过修改错误处理来跳过PHP库TCPDF和FPDI损坏的文件? [英] How to skip over corrupt files with PHP libraries TCPDF and FPDI by modifying error handling?

查看:160
本文介绍了如何通过修改错误处理来跳过PHP库TCPDF和FPDI损坏的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP库 TCPDF

I am using the PHP libraries TCPDF and FPDI to combine PDF documents, and am getting the following error:

TCPDF错误:无法在预期位置找到对象(10,0)

TCPDF ERROR: Unable to find object (10, 0) at expected location

我有 FPDI 的商业版本.

看来,此问题仅在PDF版本1.3(Acrobat 4.x)文件中发生.这是正在创建错误的文件的文档属性的屏幕快照. http://imagebin.org/215041

It appears that the issue is only happening with PDF Version 1.3 (Acrobat 4.x) files. Here is a screenshot of a file's document properties that is creating the error. http://imagebin.org/215041

我想跳过有错误的所有文件,而不是让脚本死掉.我已经使用新的类ErrorIgnoringTCPDF修改了错误处理,但是,它无法正常工作.

I'd like to skip over any files with errors instead of letting the script die. I have modified the error handling with a new class ErrorIgnoringTCPDF, however, it is not working.

有什么想法吗?

require_once('../../libraries/tcpdf/tcpdf.php');
require_once('../../libraries/fpdi/fpdi.php');

class ErrorIgnoringTCPDF extends FPDI {

   public function Error($msg) {
       // unset all class variables
       $this->_destroy(true);

       // exit program and print error
       //die('<strong>TCPDF ERROR: </strong>'.$msg);
   }

}

$pdf = new ErrorIgnoringTCPDF();
$pdf->setPrintHeader(false);

$prows = fetch_data($id);

foreach ($prows AS $row) {

    $irows = get_imaged_docs($row['pat_id']);

    foreach($irows AS $irow){

        if ($irow['type'] === 'application/pdf'){

            $doc_id = $irow['id'];

            $content = get_pdf_imaged_docs($doc_id);

            $pagecount = $pdf->setSourceFile($content);

            for ($i = 1; $i <= $pagecount; $i++) {
                 $tplidx = $pdf->ImportPage($i);
                 $s = $pdf->getTemplatesize($tplidx);
                 $pdf->AddPage('P', array($s['w'], $s['h']));
                 $pdf->useTemplate($tplidx);
            }    

        } else {

            $pdf->AddPage();

            $doc  = fetch_document_content($irow['id'], $irow['filename']);
            $img = base64_encode($doc);

            $imgdata = base64_decode($img);

            $pdf->Image('@'.$imgdata);

        }

    }

}

$pdf->Output('documents.pdf', 'D');

推荐答案

如果您使用的是Linux,则可以使用shell_exec组合文件

If you are using Linux you can use shell_exec to combine files

function combine_pdf($outputName,$fileArray)
{


         $cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$outputName ";

         foreach($fileArray as $file)
         {
           $cmd .= $file." ";
         }
         $result = shell_exec($cmd);

 }

这篇关于如何通过修改错误处理来跳过PHP库TCPDF和FPDI损坏的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆