1
votes

I have an SVG file and I want to convert it to use it in a PDF.

It is rendered well on my browsers (chrome, edge, firefox). File available here: https://gist.github.com/acourdavault/329b8670517e0716cd38eab202e2ca0e

It includes gradients enter image description here

I tried magick, inkskape, librsvg2 to convert it to png, and or pdf. the biggest problem is that stop-color and stop-color-opacity are not supported enter image description here Note, here only inkscape gives this message, the other converter don't give any information, even in verbose but the result is terrible ```bash

** (inkscape:648850): WARNING **: Unimplemented style property SP_PROP_STOP_COLOR: value: #ffa500

** (inkscape:648850): WARNING **: Unimplemented style property SP_PROP_STOP_OPACITY: value: 0.59999999999999998

** (inkscape:648850): WARNING **: Unimplemented style property SP_PROP_STOP_COLOR: value: #ffff00 ```

The PDF (to keep the format vectorial) would be ideal i guess, but i need to be able to run this from the command line.

Do you have an idea of why, this does not work and how to fix it?

Remarks I use SVG class, but the style is in a style § in the SVG itself


solution

Solution from ccprog

I moved the defs at the top of the svg xml, I used fill=url(#gradientid) to declare the gradient instead of classes I replaced the definition of the stop-color and stop-opacity that where in classes to inline them in the stop tags.

1
If it's only for this single graphic, you could also just print to file from your browser. Inkscape can import the created pdf, for example (using the poppler/cairo option gave better results in my test).Moini

1 Answers

1
votes

The issue here is that stylesheets are not well-supported by the various renderers beside browsers. You'll need to inline all styles to get this to work

Personal advertisement: I've written a node module for that task: svg-icon-toolbox. You can load your file, do the inline task and write it back with write. PDF conversion can then be done in a spawned process from the callback.

The second issue is stating the gradients after their use. It's perfectly valid according to spec, but librsvg does not like it. Inkscape will do fine. (In presence of Inkscape or librsvg on the system magick will use one of them for rendering, so that is redundant.)