SVG Graph in TCPDF is incorrectly rendered

448 Views Asked by At

I want to include an SVG image file in a TCPDF document. I draw the graph with SVGGRaph, save it to a file. Then I import the file into TCPDF.

When I view the .svg file on it's own, it is rendered correctly. However, when imported into TCPDF, the axes and tick marks are all wrong!

Why are the axes shifted? It's driving me nuts.

The svg graph is done using SVGGraph - just their simple example - see code below:

    $graph =  new Goat1000\SVGGraph\SVGGraph(500, 400);
    $graph->Values(1, 4, 8, 9, 16, 25, 27); 
    $output = $graph->fetch('LineGraph');
    file_put_contents($full_svg_image_path, $output);

Now importing into pdf document with TCPDF:

$tcpdf->ImageSVG($full_svg_image_path, $x=15, $y=100, $w=80, $h='', $link='', $align='', $palign='', $border=0, $fitonpage=false);
$tcpdf->Output($full_file_name, 'F');

Image 1 - Display the svg file directly SVG Image from File Image in TCPDF document

Image 2 - After importing into TCPDF document

1

There are 1 best solutions below

0
user1072910 On

Earlier in the code, I had setCellMargins in preparation for a table. This is what caused the text to be offset in the rendering of the SVG graph.

I did not even think about the interference. Lesson learned.