Search code examples
phphtmlpdffpdf

FPDF error: Not a JPEG file: http://10.11.201.93:81/webdocc/uploaded/tes3.jpg


I am working with fpdf to convert html to pdf . I have the following html in new.html .

<title></title>
<p><img alt="" height="364" src="http://10.11.201.93:81/webdocc/uploaded/tes3.jpg" width="496" /><img alt="" height="470" src="http://10.11.201.93:81/webdocc/uploaded/tes4.jpg" width="641" /></p>

The code to convert html to pdf is as following :

<?php
require('html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp = fopen("new.html","r");
$strContent = fread($fp, filesize("new.html"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("new.pdf");
echo "PDF file is generated successfully!";
?>

But when I run this code , I am getting the following error .

FPDF error: Not a JPEG file: http://10.11.201.93:81/webdocc/uploaded/tes3.jpg

On the following html code , I am getting error "Alpha channel not supported" .

<h1 id="sample_title"><img alt="" src="http://10.11.201.84/document-editor/uploaded/applet.PNG" style="width: 514px; height: 204px;" /></h1>

How can I remove this errors ? Please help me .


Solution

  • I also faced the same problem much time then I started to read all code of FPDF. I got my solution by changing some line fpdf.php. FPDF.php is core file in FPDF Library. So keep backup of this file before any change.

    In this file I just searched

    Not a JPEG file

    then i comment out this line and set a default value

    //$this->Error('Not a JPEG file: '.$file);

    $colspace ="DeviceRGB";

    After this, my PDF going generate. Note that in my case Image path was valid and i was upload image on S3 using base64 Decode also Croping too. so that maybe my image going working wrong. but it was being open on the browser. So after two change on fpdf.php. I got my solution.

    Another thing you have to check is the image path is valid or not. in pdf file i am using

    $pdf->Image($file,12,12,30,30);