alafr / SVG-to-PDFKit

Insert SVG into a PDF document created with PDFKit
MIT License
397 stars 111 forks source link

clipPath and masks fail on larger page sizes #185

Open pipwerks opened 5 months ago

pipwerks commented 5 months ago

Hello. Thanks for creating this utility, it has been really useful.

Just wanted to share an issue I've run into. I have an SVG containing a handful of <clipPath> and <mask>. Sometimes they work, and sometimes they don't. When they fail, they cause the rest of the page render to fail.

After playing with the online demo tool, I realized document size plays a factor. In my (limited) testing, the clip paths and masks worked fine in the default page size (US letter). My SVG is ~2200pt tall, so it gets truncated when using the US Letter page size. When I change the document size to the full height of the SVG, the rendering fails, as shown in this screenshot:

screenshot

For now, my solution is to simply strip the <def> elements from the SVG before sending to SVGtoPDF. I lose my masks and clip paths, but the rest of the file renders correctly.

Happy to provide more info or help test. Thanks

My sample SVG:

fretboard