Open Leo-Nicolle opened 6 months ago
Thank you for the bug report. It appears the SVG image is part of the exported PDF but is at the wrong location. Could you provide an example with an image tag linking a much simpler SVG that still reproduces the issue?
Sure ! Here it is !
Thanks. I could not reproduce the issue with the sandbox, though. There is a bug in your code:
const svg = document.querySelector("svg");
should be
const svg = document.querySelector("#toexport");
Otherwise, we're just exporting the first SVG. After I fixed it, the exported PDF looks fine.
Hi ! Sorry for the mistake, I might have rushed the second example a little. So I rewinded the tape, copy/pasted the cellphone SVG, and added a shape on the top left corner of it, and TADAA! Both SVG are actually exported, they are just not at the same scale as in the browser. So here is a (working + reproducing the bug) example
The SVG to export scales down the second SVG so that it fits within the view
Both SVGs are rendered in their original scale, and cropped within the view.
Thank you. I can reproduce it now. It seems like this is an issue with the viewbox transformation being applied incorrectly. If I add a viewBox attribute to the referenced image, the result is correct. I suspect the fallback case here is wrong: https://github.com/yWorks/svg2pdf.js/blob/2682632cbd3dae0ac89b40cded663187ed61ef0e/src/nodes/svg.ts#L71-L83
I'm not sure what the expected behavior is if no viewBox attribute is provided. I couldn't find much on a quick scan through the SVG spec.
I'll accept a pull request for this issue. A workaround for now might be to always set the viewBox attribute.
Describe the bug