TCPDF - images are not showing up
11,185
Old post, but I came here looking for help:
Official documentation states that all HTML attributes must be enclosed with double quotes.
width='200' height='400'
Needs to be:
width="200" height="400"
in order for the images to show. That fixed it for me.
REFERENCE: https://tcpdf.org/docs/srcdoc/TCPDF/class-TCPDF/#_writeHTML
Author by
Admin
Updated on June 06, 2022Comments
-
Admin almost 2 years
I'm trying to save a pdf with some data from database and some images. I can save normally but images are not showing up. $ft1, $ft2 and $ft3 are database variables with image's names.
Here is my test code:
require_once('../tcpdf/config/lang/bra.php'); require_once('../tcpdf/tcpdf.php'); // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 006'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 10); // add a page $pdf->AddPage(); $html.= "<div><img src='../uploads/".$ft1."' width='200' height='400' /><br><br><img src='../uploads/".$ft2."' /><br><br><img src='../../uploads/".$ft3."' /></div>"; $pdf->writeHTML($html, true, false, true, false, ''); $pdf->lastPage(); ob_clean(); $pdf->Output('../uploads/'.$norepeat.'_relatorio_'.$idcontrato.'_'.formatDataJustNumbers($_POST['datarelatorio']).'.pdf', 'F');