[thelist] how to embed Jpgraph in FPDF

jothi jothi jthjothi at yahoo.com
Thu Oct 18 07:46:14 CDT 2007

hello there,
  Thanks for those help me in posgresql...
  Now i have another problem where i used jograph to generate graphs...i am using FPDF to generate pdf files...when i try to embed the graph with FPDF ,the output was not in pdf file..below is my coding...where is the error?
  Anyone have come through this situation before?help me...
  $db_name = "wsn";
$table_name = "suhu";
  $connection = @mysql_connect("localhost", "12090", "kamala")
or die(mysql_error());
  $db = @mysql_select_db($db_name, $connection) or die(mysql_error());
  $query = "SELECT Node_ID , AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic),Date from suhu 
group by Node_ID"; 
  $result = mysql_query($query) or die(mysql_error());
  include ("c:/jpgraph-1.21b/src/jpgraph.php");    
include ("c:/jpgraph-1.21b/src/jpgraph_Line.php"); 
while($row = mysql_fetch_array($result)) 
$data[] = $row["AVG(light)"]; 
$leg[] = $row[0]; 
$graph = new Graph(250, 150,"auto");
//$graph = new Graph(600,600); 
  //$graph->SetBackgroundImage("Blue hills.jpg",BGIMG_FILLFRAME);
$lplot = new LinePlot($data); 
$lplot->SetFillColor("lightgreen"); // Fill color 
  // Put the image in a PDF page
$im = $graph->Stroke(_IMG_HANDLER);
  $pdf = pdf_new();
pdf_open_file($pdf, '');
  // Convert the GD image to somehing the
// PDFlibrary knows how to handle
$pimg = pdf_open_memory_image($pdf, $im);
  pdf_begin_page($pdf, 595, 842);
pdf_add_outline($pdf, 'Page 1');
pdf_place_image($pdf, $pimg, 0, 500, 1);
pdf_close_image($pdf, $pimg);
  $buf = pdf_get_buffer($pdf);
$len = strlen($buf);
  // Send PDF mime headers
header('Content-type: application/pdf');
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");
  // Send the content of the PDF file
echo $buf;
  // .. and clean up


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the thelist mailing list