0

It took me 12 hours still no improvement. I try displaying different images from my computer stored in the server and the result was successful. however when displaying the reports pie graph, it wont read every time the system tries to convert to pdf. It gives a blank pdf file. On the other hand, I can view the pie graph I created by using echo''; in the reports.php. I used the same concept in dompdf file but its not working.

DOMPDF

<html>
<head>
<title></title>
</head>
<body>
<?php echo'<img src="reports-display.php"/>';?>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>

JPGRAPH Drawing

<?php   
require('dbcon.php');
require_once('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_pie.php');
require_once ('jpgraph/src/jpgraph_pie3d.php');


//LEGEND
//YELLOW=LIVE BLUE=WAITING GREEN=DONE


//sql query for live
$live = mysql_query("Select count(*) as count1 from tbl_display_ads where status LIKE '%Live%'") or die(mysql_error());


//sql query for waiting
$waiting = mysql_query("Select count(*) as count2 from tbl_display_ads where status LIKE '%Waiting%'") or die(mysql_error());


//sql query for done/posted advertisement
$done = mysql_query("Select count(*) as count3 from tbl_display_ads where status LIKE '%Done%'") or die(mysql_error());

//While loop for live
while($resultlive = mysql_fetch_array($live)) 
{ 
    $totallive = $resultlive['count1']; 
} 

//While loop for waiting
while($resultwaiting = mysql_fetch_array($waiting)) 
{ 
    $totalwaiting = $resultwaiting['count2']; 
}

//While loop for done
while($resultdone = mysql_fetch_array($done)) 
{ 
    $totaldone = $resultdone['count3']; 
}

// Some data
$data = array($totallive,$totalwaiting,$totaldone);

// Create the Pie Graph. 

$graph = new PieGraph(500,450);

$theme_class= new VividTheme;
$graph->SetTheme($theme_class);

// Set A title for the plot
$graph->title->Set("Figure 1.1: Totality of Display Advertisement");

// Create
$p1 = new PiePlot3D($data); 
$p1->SetCenter(0.5,0.55);

$p1->SetLegends(array("Live","Waiting","Done"));
$graph->legend->SetPos(0.5,0.100,'center','bottom');
$graph->Add($p1);
$p1->ShowBorder();
$p1->SetColor('black');
$p1->ExplodeSlice(1);
$graph->Stroke();

// Get the handler to prevent the library from sending the
// image to the browser
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);

// Stroke image to a file and browser

// Default is PNG so use ".png" as suffix
$fileName = "/tmp/imagefile.png";
$graph->img->Stream($fileName);

// Send it back to browser
$graph->img->Headers();
$graph->img->Stream();


?>
Mark
  • 11
  • 5

2 Answers2

0

I finally found out the solution. in the report-display.php I set the extension name of the graph to .png and save to the directory folder for reports.

 DEFINE("DEFAULT_GFORMAT","auto");
$graph->img->SetImgFormat("png");
if(file_exists("Reports/reports-display.png")) unlink("Reports/reports-display.png");
$graph->Stroke("Reports/reports-display.png");
Mark
  • 11
  • 5
0

The problem is that you're essentially asking dompdf to grab an image file called "reports-display.php" from the local filesystem. When you use $dompdf->load_html() dompdf has no idea where the content arrives from. Any resource references in the HTML that lack a full URL are pulled in via the local filesystem. Since dompdf does not parse the PHP the source will be read in, which is obviously not a valid image document.

You're found a valid solution in saving the file locally. There are two other possibilities:

1) Point to the jpgraph script through your web server.

<html>
<head>
  <title></title>
</head>
<body>
  <img src="http://example.com/reports-display.php"/>
</body>
</html>

2) Capture the jpgraph output and insert into the document as a data-uri.

<html>
<head>
  <title></title>
</head>
<body>
  <img src="data:image/png;base64,<?php echo base64_encode(include_once('reports-display.php');?>"/>
</body>
</html>

With this method reports-deplay.php would have to be updated to return the image rather than stream it. Something like:

$graph = new PieGraph(500,450);

// snip steps that generate the content

return $graph->Stroke();
Community
  • 1
  • 1
BrianS
  • 13,284
  • 15
  • 62
  • 125