0

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>
Jay Shri
  • 119
  • 3
  • 12

1 Answers1

1

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.
Jan Slabon
  • 4,736
  • 2
  • 14
  • 29
  • using `use setasign\Fpdi\Fpdi;` + getting FPDF and requiring FPDF.php worked. I changed output() to output(directory, 'F') to save the file. Thanks – Jay Shri Apr 12 '18 at 17:02