Generate graphs in PDF file using TCPDF
There are tons of topics on this, none of which have solved my issue. What
I'd like to do is simple - generate a bar graph and then embed this graph
into a pdf file that I will be generating with a library called enter link
description here.
I'm having no problems generating HTML content using TCPDF but when it
comes to generating the graph and including it in the pdf file, I'm having
all kinds of issues.
Generating the graph
I'm creating the graph using a library called svggraph. Generating the
graph is very simple, the only problem is that there are headers being
sent through the inclusion of the main class file. When headers are sent,
TCPDF cannot generate the PDF document.
My setup now:
generatereport.php - TCPDF generates the pdf document on this page
graph.php - SVGGraph generates the bar graph on this page
I've tried:
file_get_contents('graph.php') from generatereport.php - nothing is being
output in the pdf report when I use the built in writeHTML function that
TCPDF offers
require_once('graph.php') - headers already sent error
echo file_get_contents('graph.php') - Headers already sent, but that was
expected. The good news is that the graph was displayed properly.
Goal (What I'd like to happen) TCPDF has a built in ImageSVG function that
is used for this exact purpose. The first parameter can take a XML string
of SVG data; the problem here is that I can't figure out how to return XML
data from the graph.php page (I've read every documentation page I could
find).
Does anyone have any experience using either of these two libraries?
Thanks!
Edit: Some code
Graph.php:
<?php
require_once 'svggraph/SVGGraph.php';
$graph = new SVGGraph(500, 400);
$graph->Values(1, 4, 8, 9, 16, 25, 27);
$graph->Render('LineGraph', true, true)
?>
generatereport.php
$html = file_get_contents('http://localhost:8080/vu/graph.php');
if(!empty($file)){
//$pdf->Write(0, $html, '', 0, 'L', true, 0, false, false, 0);
//$pdf->writeHTML($html, true, false, true, false, '');
$pdf->ImageSVG('@' . $html, $x=15, $y=30, $w='', $h='',
$link='http://www.tcpdf.org', $align='', $palign='', $border=1,
$fitonpage=false);
}
The @ symbol tells the function that XML data is being sent to it, as
opposed to an SVG file.
No comments:
Post a Comment