There are many topics in this, none of which solved my problem. What I would like to do is simply generate a histogram, and then paste this graph into a pdf file, which I will generate using the TCPDF library.
I have no problem creating HTML content using TCPDF, but when it comes to creating a graph and including it in a pdf file, I have all kinds of problems.
Graph generation
I am creating a graph using the svggraph library. Generating a graph is very simple, the only problem is that the headers are sent via the inclusion of the main class file. When headers are sent, TCPDF cannot create a PDF document.
My setup now:
generatereport.php - TCPDF creates a pdf document on this page graph.php - SVGGraph generates a histogram on this page
I tried:
file_get_contents('graph.php') from generatereport.php - nothing is output in the pdf report when I use the built-in writeHTML function that TCPDF offers- require_once ('graph.php') - headers already sent
echo file_get_contents('graph.php') - Headers have already been sent, but this was expected. The good news is that the graph has been correctly displayed.
Target (what I would like) TCPDF has a built-in ImageSVG function that is used for this purpose. The first parameter can accept an SVG XML data string; the problem is that I cannot figure out how to return the XML data from the graph.php page (I read every page of the documentation I could find).
Does anyone have any experience using either of these two libraries?
Thanks!
Edit: 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 indicates to the function that XML data is sent to it, unlike an SVG file.