4 ms·
That’s pretty crazy. PDF is a vector format so rendering SVG to a bitmap to insert into it is like using email to send a photo of a fax. Seems like you’re alrea
by jahewson 4y ago
That’s pretty crazy. PDF is a vector format so rendering SVG to a bitmap to insert into it is like using email to send a photo of a fax. Seems like you’re already aware of that though!
There’s many libraries out there that can convert vector SVG directly to vector PDF. Sometimes it’s worth just paying the license for, say pdftron. Alternatively if you are generating the would-be SVG content in JS you could directly generate PDF instead of SVG with http://pdfkit.org/ http://pdfkit.org/
Chrome usually does a good job rendering SVG directly to PDF. It’s overkill of course, but if you’re already used to using it then it’s the path of least resistance. If you’re getting giant PDFs output then I suspect there’s something weird with your input SVG. It might contain some pathological content (huge embedded images? paths with large amounts of almost invisible details? fonts that aren’t embedded sensibly? e.g. vectors of every glyph)
- vbezhenar 4y agoNo, that image is pretty primitive. Lots of lines, lots of dots (tiny circles), some polylines, few text labels. Nothing fancy at all. I dont really want to turn entire document into svg. There’s some text, some tables, things that fit perfectly for HTML and not so much for SVG. Right now I’m thinking about using GNU groff. It would be a very different approach.
- jahewson 4y agoThat’s understandable. Maybe try commenting out all the generating code and adding it back piece by piece until the document size balloons, then you’ve found your culprit. The MuPDF ‘mutool’ is pretty handy for dumping internal PDF content to see which parts are large.