简体   繁体   中英

500 Internal Server Error on $pdf->setSourceFile()

I want to add a png-image to an existing pdf file. Therefore I'm trying to integrate FPDI/FPDF into my project, that is based on the SLIM framework with ELOQUENT.

FPDI/FPDF is added with composer ( composer require setasign/fpdi-fpdf ).

I successfully testet the following code in a single php file ("pdf_test.php") directly opened in the browser:

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

$pdf = new FPDI();
$filename = '1005236946.pdf';
$pageCount = $pdf->setSourceFile($filename);
$templateId = $pdf->importPage(1);
$pdf->useTemplate($templateId);
$pdf->Image('9959544245.png',268,184,20, 'PNG');
$pdf->Output('F', '1005236946_PNG.pdf');

But when I use this code in SLIM route ("/php_test") I get a "500 Internal Server Error" at this point:

$pageCount = $pdf->setSourceFile($filename);

I've checked that the $pdf-object is created well.

I searched the web but found nothing so far that could help. Maybe it has to do something with the Apache Server and the .htaccess file... ?

Any help very appreciated :-)

error_log: PHP Warning: require(../app/models/pdf_parser.php):

This means that the autoload implementation doesn't check if a file exists and simply requires it. Because of such strange implementation a simple class_exist() call (which is the case here) on an not existing class will produce this error.

So fix the autoload implementation or require the parser separately:

require_once('../vendor/setasign/fpdi/pdf_parser.php');

Also I'm unsure why you require both script manually and why you do not use the autoloader of composer. (Wouldn't change the behaviour but would make more sense)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM