0

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

user1072910
  • 263
  • 1
  • 5
  • 17
  • Can you modify the svg file? I belive the problem is the text alignement. Please make sure that text-anchor="end" – enxaneta Jan 30 '22 at 08:30
  • @enxaneta - I checked the svg file and text-anchor is correctly set to "end" and so it displays correctly when I just display the svg file in the browser. Would TCPDF change this? Can I override it? – user1072910 Jan 30 '22 at 19:23

1 Answers1

0

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.

user1072910
  • 263
  • 1
  • 5
  • 17