svgToPdf.js icon indicating copy to clipboard operation
svgToPdf.js copied to clipboard

Add support for <path>

Open aendra-rininsland opened this issue 10 years ago • 11 comments

It seems svgToPdf isn't able to render <path> elements. Particularly for those of us doing data visualisation, being able to render splines is incredibly important.

aendra-rininsland avatar Jan 14 '15 15:01 aendra-rininsland

I didn't implement this in the first place because the pdfjs library didn't have support for bezier curves and complex filled elements (only rectangles and circles).

But if you have an idea on how to do it, don't hesitate to propose it!

cbix avatar Jan 14 '15 15:01 cbix

@CBiX Figured as much, though it seems possible to do multi-segment lines See http://mrrio.github.io/jsPDF/doc/symbols/jsPDF.html#lines

Will play with it and get back to you...

aendra-rininsland avatar Jan 14 '15 15:01 aendra-rininsland

@aendrew Maybe we should one day switch vrom jsPDF to http://devongovett.github.io/pdfkit/ As far as I see it has everything you might need...

cbix avatar Jan 14 '15 19:01 cbix

@CBiX I totally ran across that today and nearly used it in a project. In the end I rendered SVG to Canvas and from that to PNG, which I used jsPDF to put into Canvas. Totally not the best way of doing things, but you'd have to basically write a DOM walker to get it to work with PDFKit. Which, TBH, isn't at all a half-bad idea — at the moment, there's no simple way to easily push a SVG doc into PDFKit and then have it spit out a PDF. Which is a shame, because PDFKit is so much better documented than jsPDF and has the ability to draw any kind of SVG path using the exact same syntax as SVG. It can even do clipping masks, which is totally crazy.

The one thing I'm not sure how to approach with PDFKit is group elements, which allow something to be translated in a particular direction (something I do pretty frequently with SVG). I'm not sure how you'd handle a translated group with PDFKit...

aendra-rininsland avatar Jan 14 '15 22:01 aendra-rininsland

Hi, would it be easy to support filled polygons? ( no beziers)

goswinr avatar Nov 15 '15 14:11 goswinr

@gwinsky Not with jsPDF, see comments above :)

cbix avatar Nov 15 '15 14:11 cbix

So I guess it wont ever be added ?

LukyVj avatar Jan 04 '17 11:01 LukyVj

Here is code from my (unrelated) project which parses an SVG path (no curves as of writing, but planned). If this function returns a path, simply call pdf.lines(path.acc, path.x1, path.y1, [1, 1], 'DF', path.closed);, where pdf is the jsPDF object. Replace 'DF' as needed.

phihag avatar Sep 02 '17 01:09 phihag

Hmm. Is this issue still active?

Uzlopak avatar Jun 13 '18 09:06 Uzlopak

I fixed it for my own use. but it's not perfect now. Can I send a PR? @CBiX

It supports MmLlQqCcZz commands but not HhVvAaTtSs yet. And It doen't support holes in path. All holes will be treated as normal shape. Please let me know if you guys have ideas to handle with holes.


update: All path commands are supported well except arc(A,a). The arc command will be treated as straight line.

cuixiping avatar Jan 14 '20 08:01 cuixiping

Sure, however, I'm not actively maintaining this project anymore. Will try to look into it tho :) Thanks for your work!

cbix avatar Jan 15 '20 03:01 cbix