svg2pdf icon indicating copy to clipboard operation
svg2pdf copied to clipboard

Text element support

Open topochico-one opened this issue 2 years ago • 3 comments

Thanks for creating svg2pdf! Does it support text elements? I get a blank PDF when I try to convert the following SVG:

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink" 
     width="600" height="300">
<text x="0" y="15" fill="red">I love SVG</text>
</svg>

topochico-one avatar Jul 22 '22 21:07 topochico-one

svg2pdf uses usvg behind the scenes to convert the SVG to a simpler representation. This also includes converting text to curves. So to correctly render text, you have to manually create a usvg::Tree from your string (providing fonts) and then use convert_tree instead of convert_str. You can see how it's done in svg2pdf's CLI here.

laurmaedje avatar Jul 22 '22 21:07 laurmaedje

This should probably be explained in the documentation, we can keep this issue open to track that.

laurmaedje avatar Jul 22 '22 21:07 laurmaedje

Ah this makes sense! Thank you for the super fast response!

topochico-one avatar Jul 22 '22 22:07 topochico-one