Jump to content

Trying to use DOMPDF for my reports, doesn't work with images


DWilliams

Recommended Posts

I've tried posting this on the DOMPDF newsgroup but it's not very populated and I haven't had a response yet. I'm hoping somebody here has worked with DOMPDF before.

 

I'm using DOMPDF to make PDF reports. Everything works great except

images.

 

Here is the relevant portion of my code:

 

$reportHTML = getReportHTML();

// Check to see if a PDF was requested 
if($_GET['target'] == 'pdf') 
{ 
  // User is requesting a PDF download, create the PDF structure and send it to them 
  $reportHTML = '<html><body style="margin: 2em;"> 
                 <img src="/var/www/images/logoheader.gif" style="width:200px;height:200px"> 
                 <table width="100%" style="background-color:#000; color:#FFF; font-weight:bolder; font-size:150%; 
                 text-align:center"><tr><td>' . $reportConfig['title'] . '</td></tr></table>' . $reportHTML . '</body></html>'; 
  ob_clean(); 
  require_once('lib/dompdf/dompdf_config.inc.php'); 
  $pdf = new DOMPDF(); 
  $pdf->load_html($reportHTML); 
  $pdf->render(); 
  $pdf->stream(strtolower(str_replace(' ', '_', $reportConfig['title'])) . '_' . date('n/j/y-G:i') . '.pdf'); 

}

 

This works absolutely fine if I remove the <img> element in

$reportHTML. As soon as I add it back in, I get a blank white page

instead of a PDF when I run the report. That image is indeed at that

path and is indeed a working image. I've tried it with other images,

nothing works. I've tried both absolute and relative paths.

 

I've googled this problem and haven't found any solutions. I found one

suggestion saying to make sure that DOMPDF's temp directory is

writeable by the webserver, and I verified that the temp directory is

set to /tmp and www-data can write to it.

 

How can I get images on my reports? It looks pretty bad without our

logo for obvious reasons.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.