Closed vitto closed 2 years ago
Just stumbled upon this. I'm doing the exact same thing for quite some time now. No clue as to why I've had to do it though 😅
Well, this just bit me. What we were doing with widthScaled
isn't actually correct. I've found the solution here: https://github.com/alafr/SVG-to-PDFKit/issues/102
The problem is that PDF's are in points
and SVG's are in pixels
. 24px equals 18pt (18/24 = 0.75).
What I had to do in my case is keep the width as is and add the option { assumePt: true }
.
const doc = new PDFDocument({
size: [24, 24],
});
SVGtoPDF(doc, svg, 0, 0, { assumePt: true });
It worked! Thank you, I didn't found this option before. Solved.
For some reason, when I create the insert the SVG in the PDF file it build the document with margins to the left and bottom:
I've solved the problem just by adding an hardcoded margin by my hand with
widthScaled
but I'm pretty sure there is something I'm missing, because it doesn't seems to be the right way to fix my problem:It works, but I don't know why I have to do it.