SVG-to-PDFKit icon indicating copy to clipboard operation
SVG-to-PDFKit copied to clipboard

Resize/scale SVG?

Open niftylettuce opened this issue 5 years ago • 2 comments

It looks like this is related to https://github.com/alafr/SVG-to-PDFKit/issues/24, but passing a width and height doesn't seem to work. Can we get proper instructions for how to achieve this added to the README?

niftylettuce avatar Jul 21 '20 01:07 niftylettuce

Doesn't work for me, either; I had to size the drawing in the SVG.

antefix-consulting avatar Jan 10 '21 03:01 antefix-consulting

When the SVG has its width and height attributes set they are used no matter what you specify in the options. Only when the SVG has no width and height attributes and only the viewport it works. But instead of preprocessing the SVGs, I figured out that you have to specify the preserveAspectRatio to match the same width and height you want to have:

this.doc.addSVG(src, x, y, {
  width,
  height,
  preserveAspectRatio: `${width}x${height}`,
});

At least in my use case, it worked

Simolation avatar Apr 04 '21 11:04 Simolation