Search code examples
tcpdf

The imageSVG() method of tcpdf is not rendering correctly the svg file


I have the following svg file:

http://jsfiddle.net/wptn28c5/

<svg></svg>

that renders:

svg output

However, by using tcpdf ($pdf->imageSVG()) i get a pdf file that renders:

pdf output


Solution

  • The SVG standard is not fully implemented in TCPDF, so not all SVGs will render correctly inside TCPDF as is. For those cases you'll either need to use setRasterizeVectorImages (requires ImageMagick) to rasterize the SVG on the fly for you - or tweak the SVG into a form that would work.

    With this specific file, I suspect that the complexity of the path was the issue. Though, I'm not entirely sure. I made you a new SVG file that works in the latest version of TCPDF. I saved it in a JSFiddle here. Basically, I took the path and broke it out into individual elements using InkScape.

    To do this, I entered the transform group, selected the path, and finally chose "Break Apart from the Path menu.