piqnt / svgexport

SVG to PNG/JPEG command-line tool and Node.js module
927 stars 85 forks source link

Add support for PDF output #78

Open potatosalad opened 4 years ago

potatosalad commented 4 years ago

I realize that PDF support was previously supported and later removed, but I had a need for SVG 1.1 to PDF conversion support and thought it might be worth revisiting.

This tool, in my opinion, produces the most accurate PDF results in comparison with other tools I've tried (rsvg, cairosvg, svglib, and many others).

Main change is that CSS on the SVG element itself for transform: translateX(${-clip.x}px) translateY(${-clip.y}px) compared with modifying the left and top style properties on the outputEl itself.

This allows us to use page.pdf for PDF output and continue to use elementHandle.screenshot for PNG and JPEG output.

shakiba commented 4 years ago

Sorry for delay and thanks for making the PR, it looks great. One question that I have is that how converting svg to pdf is different from converting to png/jpeg and then converting image to pdf.

potatosalad commented 4 years ago

PNG to PDF results in a rasterized version of the image that is not as suitable for printing. Writing straight to PDF results in a vectorized version of the image.

shakiba commented 4 years ago

Oh, very interesting! So yes, this is useful. I will merge it soon.