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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度