jangko / nimpdf

PDF document writer, written in nim lang
Other
169 stars 10 forks source link

Adding SVGs #44

Open PMunch opened 1 month ago

PMunch commented 1 month ago

I've been using this to create some PDFs for notebooks where I design the individual pages through a combination of scripts and manual SVG work. I then convert all my pages to PNG and have a script witch stitches them together as a PDF. However that requires me to select the DPI of the images when I convert them, it would be much better to add the vector graphics directly to the PDF. Would it be possible to add SVG support, or alternatively PDF-as-images support so I can convert my SVGs to PDFs and then lay them out with this?

jangko commented 1 month ago

You need to write your own SVG renderer. Adding it to PDF is beyond the scope of a PDF writer. you can see the example of converting SVG to vector graphics primitives here: https://github.com/jangko/nimAGG/blob/devel/examples/svg_path_renderer.nim it should be similar when using PDF api.

PMunch commented 1 month ago

Hmm, fair enough. But what about converting the SVGs to PDF first, and then laying out the smaller PDFs in a larger one using this library?

jangko commented 1 month ago

scale, move, rotate, stretch, skew, and setTransform + saveState and restoreState should work. You do the transformation on the fly, not after converting to PDF. This is not a PDF reader library.