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

CSS import rule throws #177

Closed DrixnFS closed 3 years ago

DrixnFS commented 3 years ago

I have the following problem: Hello community, iam trying to find a library that will allow me to convert my custom made svgs into PDFs and stay svg and i went by this. I tried the online demo and tried to implement it in my project but both gives me the same error of : Cannot read property 'indexOf' of undefined inside a stylesheets.ts:76 so its internall error. I tried sanitazing the SVG and it does the same. In every matter it should be valid SVG but its huge one

image svg.txt Basically this is the svg as picture what iam trying to get. and also adding the source of the svg if anyone would have any idea how to workaround the issue or what exactly iam missing it would mean the world to me Thanks alot community

yGuy commented 3 years ago

The problem is the @import in the CSS which is not supported. We expect a selector text but this is undefined. Removing the @import gets rid of the exception. Small test-case

DrixnFS commented 3 years ago

Hello there,

So sorry i took so long but iam super swamped currently. I tried to get rid of that import line and it in fact removed the issue with the exception but for some reason in the end all i get is a blank PDF. I'll look into it more closely to find what causes that as there is no exception this time and the SVG element is there as ive debugged so far. EDIT: When i use third party webpage like https://cloudconvert.com/svg-to-pdf to convert the SVG to PDF it exports perfectly so i need to find the issue in the lib

lucaslar commented 3 years ago

Hello there, I'm facing the same error even though I don't have any @import. Instead, @font-face causes the problem → if I take it out, it works, but, obviously, the PDF is not looking as good as it should. Is this intended to be fixed, i.e. are external ressources automatically to be inlined on generating a PDF?

In my case, I'm "printing" a current part of the screen (dom → svg → pdf - the latter step using this package). For the first step, I found another really good package which also allows to inline external resources (dom-to-svg). @DrixnFS Perhaps this works for you, too!