title: Generate graphs in PDF file using TCPDF
body: <p>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 <a href="http://www.tcpdf.org/">TCPDF</a>.</p>
  
  <p>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.</p>
  
  <p><strong>Generating the graph</strong></p>
  
  <p>I'm creating the graph using a library called <a href="http://www.goat1000.com/svggraph-using.php#reference">svggraph</a>. 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.</p>
  
  <p>My setup now:</p>
  
  <p>generatereport.php - TCPDF generates the pdf document on this page
  graph.php - SVGGraph generates the bar graph on this page</p>
  
  <p>I've tried:</p>
  
  <ul>
  <li><code>file_get_contents('graph.php')</code> from <code>generatereport.php</code> - nothing is being output in the pdf report when I use the built in <code>writeHTML</code> function that TCPDF offers</li>
  <li>require_once('graph.php') - headers already sent error</li>
  <li><code>echo file_get_contents('graph.php')</code> - Headers already sent, but that was expected. The good news is that the graph was displayed properly.</li>
  </ul>
  
  <p><strong>Goal (What I'd like to happen)</strong>
  TCPDF has a built in <code>ImageSVG</code> 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 <code>graph.php</code> page (I've read every documentation page I could find).</p>
  
  <p>Does anyone have any experience using either of these two libraries?</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit: Some code</strong></p>
  
  <p>Graph.php:</p>
  
  <pre><code>&lt;?php
  require_once 'svggraph/SVGGraph.php';
  $graph = new SVGGraph(500, 400);
  $graph-&gt;Values(1, 4, 8, 9, 16, 25, 27); 
  $graph-&gt;Render('LineGraph', true, true)
  ?&gt;
  </code></pre>
  
  <p>generatereport.php</p>
  
  <pre><code>$html = file_get_contents('http://localhost:8080/vu/graph.php');
  
  if(!empty($file)){
  //$pdf-&gt;Write(0, $html, '', 0, 'L', true, 0, false, false, 0);
  //$pdf-&gt;writeHTML($html, true, false, true, false, ''); 
  $pdf-&gt;ImageSVG('@' . $html, $x=15, $y=30, $w='', $h='', $link='http://www.tcpdf.org', $align='', $palign='', $border=1, $fitonpage=false);
  }
  </code></pre>
  
  <p>The <code>@</code> symbol tells the function that XML data is being sent to it, as opposed to an SVG file.</p>