Question

I am using the Wordpress plugin post-to-pdf to generate pdf reports, and that uses dompdf to make the pdfs. I have added a graph to the reports using phplot. The graphs convert to pdf fine but the rest of the report is gone and I cant resize the graph. I tried wrapping the graph as an image. Any ideas?

//The graph function
function graphmaker(){
// Include Graph
include( PDFEXPORT_PLUGIN_PATH.'/graph/phplot/phplot.php' );
//Define the object
$plot = new PHPlot(800,600);
//Define some data
$example_data = array(
array('a',3),
array('b',5),
array('c',7),
array('d',8),
array('e',2),
array('f',6),
array('g',7)
);
$plot->SetDataValues($example_data);
//Turn off X axis ticks and labels because they get in the way:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
//Draw it
$plot->DrawGraph();}

return '<img src="'. graphmaker() .'" width="200" height="200">';

When I look at the code the PDF's make %PDF-1.3 is being replaced by %PNG on the top line?

Was it helpful?

Solution

After a day struggling with graphs in PDFs I finally got it working. I imagine its not the sort of fix most of you would pick, but it fixed my problem and may hep someone else.

I switched to jpgraph and uploaded it to a different server(for some reason I couldnt get it working on my the same server as dompdf). I put the graph making code in a file on the jpgraph server and called the file graphmaker.php. I summoned graphmaker.php in the html that makes the dompdf pdf.

<img style="padding-left:60px;" src="http://mydomain.com/chart/jpgraph/graphmaker.php?a='.$prog1.'&b='.$prog2.'&c='.$prog3.'&d='.$prog4.'&e='.$prog5.'&f='.$prog6.'&g='.$prog7.'&h='.$prog8.'&i='.$prog9.'&j='.$prog10.'&k='.$prog11.'&aa='.$well1.'&bb='.$well2.'&cc='.$well3.'&dd='.$well4.'&ee='.$well5.'&ff='.$well6.'&gg='.$well7.'&hh='.$well8.'&ii='.$well9.'&jj='.$well10.'&kk='.$well11.'">

The crazy bit on the end is an array of two sets of variables to draw my line graphs with.

In graphmaker.php the first thing I did was parse the URL:

$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$parsedurl =  parse_url($url, PHP_URL_QUERY);

parse_str($parsedurl);

Parsing the URL gave me $a, $b, $c, etc variables which are storing the line graph info the graph needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top