Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and FPDI/FPDF: Fatal error: Uncaught Exception: FPDF error: Incorrect output destination

Tags:

php

pdf

fpdf

fpdi

I have a PDF file, and I want to add a new page with FPDI/FPDF

Fatal error: Uncaught Exception: FPDF error: Incorrect output destination: outfiles/111111.pdf in C:\wamp\www\pdf\fpdi\fpdf.php on line 271 ( ! ) Exception: FPDF error: Incorrect output destination: outfiles/111111.pdf in C:\wamp\www\pdf\fpdi\fpdf.php on line 271

require_once('fpdi/fpdf.php');
require_once('fpdi/fpdi.php');

foreach(glob('infiles/*.pdf') as $file)
{
    $filename = basename($file);
    $fileout = 'outfiles/' . $filename;
    //echo $fileout;
    $out = new FPDI();

    $pagecount = $out->setSourceFile($file);

    for($i = 1; $i <= $pagecount; $i++)
    {
        $tpl = $out->importPage($i); 

        $out->addPage($format);
        $out->useTemplate($tpl);

        if($i < $pagecount)
        {
            $out->addPage($format);
        }
    }

    $out->Output($fileout);
}
like image 298
user3282262 Avatar asked Aug 18 '17 09:08

user3282262


1 Answers

The Output() method requires the first parameter to be the destination and the snd parameter the filename.

So just change the line to:

$out->Output('F', $fileout);

Additionally you should know that you cannot modify a PDF document with FPDI but you import the pages into a reusable structure. Your resulting PDF is a completely new PDF document and you'd not added new pages to the original one.

like image 148
Jan Slabon Avatar answered Oct 01 '22 10:10

Jan Slabon