yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
649 stars 98 forks source link

Support for css class tag in SVG #162

Closed FHoffmannSopra closed 3 years ago

FHoffmannSopra commented 3 years ago

Hey guys,

I tried to render a ccs-styled polyline with the svg2pdf tool.

<polyline points="125.5,112.55411200000003 125.5,142.55411200000003 125.5,212.62911200000002 126,212.62911200000002 126,282.704112 126,312.704112" fill="none" class="test"></polyline>

Whenever I use a css-class the polyline is not rendered at all. The css class is just a change to the color of the polyline, I wanted to make it as simple as possible.

I just need the info, if there is support for such statements at all, because in my case it is essential to use css classes to style my elements.

I am using svg2pdf 2.0.0 and jsPdf 2.0.0.

Thanks for your help Frederic

HackbrettXXX commented 3 years ago

In theory, classes are supported. Where are your styles defined? svg2pdf supports SVG style, link, and xml-stylesheet tags. For link and xml-stylesheet tags you need to enable the loadExternalStylesheets option. Note, that styles in the HTML of your webpage are not picked up. The styles need to be defined or referenced in the SVG itself.

yGuy commented 3 years ago

Works for me with my simple test: test it in Playground

FHoffmannSopra commented 3 years ago

Thanks for your superfast reply.

My styles are defined in a seperate css file, so they are not referenced in the Svg itself. I guess that is the issue in my case. So the key is to change the way I create the Svg.