douyou1857 2018-04-11 18:09
浏览 87
已采纳

FPDI无法初始化新的FPDI()对象

I'm trying to remove the second page from multiple pdfs. I get a 500 error on this page when I include the line $pdf = new FPDI(); and anything afterwards. The path to the autoload.php is right, so I do not know what I am doing wrong.

I cut out array declarations for space. There is nothing else in the doc other than that.

<?php

require_once('includes/fpdi/autoload.php');
ini_set('memory_limit', '1024M');
ini_set('max_execution_time', 120); //

$i = 0;
foreach ($arrFiles as &$value) {

    $destination=fopen($documentroot."attachments/".$FileNames[$i],"w");
    $remote = $arrFiles[$i];
    $local  = $documentroot."attachments/".$FileNames[$i];
    copy($remote, $local);
    fclose($destination);

     $pdf = new FPDI();
     // $pageCount = $pdf->setSourceFile($documentroot."attachments/".$FileNames[$i]);
     //$templateID = $pdf->importPage(1);
     //$pdf->getTemplateSize($templateID);
     //$pdf->addPage();
     //$pdf->useTemplate($templateID);
     // $pdf->Output();
}
?>
<html>
<head>
<title></title>
</head>

<body>
 Hello
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongxi2014 2018-04-12 08:19
    关注

    Add

    use setasign\Fpdi\Fpdi;
    

    to the top of your script and initiate Fpdi.

    FPDI 2 is namespaced.

    There are several other issues in your snipped:

    1. The Output() call will send the file to the client. Doing this in a loop looks faulty!
    2. NEVER output any other content (the bunch of HTML at the eof) after sending the PDF to the client.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测