printpdf
printpdf copied to clipboard
SVG example
Hey,
Would be great with a example for rendering SVG.
Embedding SVG doesn't work yet. You can use the svg crate, iterate over the paths and then use build a Vec<Point> from those. This functionality should be moved into the library later on, for drawing symbols. I'll get it done some time later. Thanks for the reminder.
Ah I see, would it be good to have an example of using the svg with printpdf?
Yeah it's in the code already, it just doesn't have an interface to the LayerReference, because I didn't have time: https://github.com/sharazam/printpdf/blob/master/src/types/plugins/graphics/two_dimensional/svg.rs
There is a commented-out function add_svg() already: https://github.com/sharazam/printpdf/blob/master/src/types/pdf_layer.rs#L83 but this is for library-internal use.
Since SVG elements are often repeated on a page, I tried seperating them out into a FormXObject, but I failed so far (PDF errors). I'll definitely try again later on. You could remove the pub(crate) things and try it at your own risk. Metrics in SVG are hard.
Not sure if it works, didn't test it. Code is half taken from the example code that svg provides.
Alright, I can try that out. Thank you! :)
I'll add SVG later on. Right now my workaround is to put the SVG element in a font (manually) and then use the font. For "proper" SVG support you'll probably also need gradients. But for monochrome symbols, the font approach works, too.