Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svg2pdf incorrect width and height output - #415

Open
xvdp opened this issue Mar 1, 2024 · 1 comment
Open

svg2pdf incorrect width and height output - #415

xvdp opened this issue Mar 1, 2024 · 1 comment

Comments

@xvdp
Copy link

xvdp commented Mar 1, 2024

I have an svg file with attributes
width="1929" height="2572"
which I created as a bytestring or as a file

cairosvg.svg2pdf(svgstr, write_to="svg_0.pdf")
svg_0.pdf comes out with 'width': 1446.75, 'height': 1929

I looked thru the code and I noticed that the svg2pdf(dpi=96) default, cairosvg UNITS['pt'] will scale to 72dpi.
If my svg has no mention of dpi, or units, why should it be assumed that one wishes to scale ?

fix to the unit assumption is to just pass dpi=72

@liZe
Copy link
Member

liZe commented Mar 2, 2024

Hi!

svg_0.pdf comes out with 'width': 1446.75, 'height': 1929

The size of a PDF page is stored in inches, so it’s not possible to give a PDF size in pixels without using an arbitrary DPI value.

96 is the default value CairoSVG uses, because that’s the one used in CSS (1 inch = 96 px). You have to set 72 if you want 72. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants