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

units in page size don't work any more #2006

Closed
bernharduw opened this issue Sep 5, 2022 · 6 comments · Fixed by #2771
Closed

units in page size don't work any more #2006

bernharduw opened this issue Sep 5, 2022 · 6 comments · Fixed by #2771

Comments

@bernharduw
Copy link

bernharduw commented Sep 5, 2022

Describe the bug
Variable dpi support in #1869 removed support for page sizes with units such as mm. The units should be converted to points before dividing by dpi.

To reproduce
These pages should be the same size, but the first one has invalid dimensions:

    <Page size={{ width:"105mm", height:"148.5mm" }} debug/>
    <Page size="A6" debug/>

Here's the react-pdf REPL snippet.

Expected behavior
mm values in page sizes should work as in @react-pdf/renderer@2.x and @react-pdf/layout@3.1.x.

Desktop (please complete the following information):

  • OS: all
  • Browser: all
  • React-pdf version 3.0.0
@bernharduw bernharduw changed the title pages with units don't work any more units in page size don't work any more Sep 5, 2022
@aditfurk
Copy link

aditfurk commented Sep 6, 2022

Hi, i've countered the same problem, so right now how can i create custom page size? thanks...

@bernharduw
Copy link
Author

Hi, i've countered the same problem, so right now how can i create custom page size? thanks...

@aditfurk one workaround is to use numeric units and convert the units to points. 1in = 72pt, and 2.54cm = 1in. So if you wanted to define a custom page size that is 10x14in, you can use <Page size={[10*72, 14*72]}></Page>.

For our use case though, this is not a viable solution because we have a large library of PDF templates that would have to be rewritten. I'm hoping for a PR to fix the issue in react-pdf instead.

@aditfurk
Copy link

aditfurk commented Sep 6, 2022

@bernharduw ahh okay, thanks for the answer

@klimeryk
Copy link

klimeryk commented Jan 9, 2023

Same here - page size specified in mm used to work, but it seems that since 3.* it's broken. Setting it to points after manually converting as @bernharduw does not solve my issue. The page size seems better but the height of items does not seem correct. If I set the same points size using renderer@2.3.0 the page looks perfect.
If there's a breaking change somewhere from 3.0.0 I'd love to know where - and have it documented in the release notes. I went through them and could not find anything clearly stated. 2.* to 3.* is a major upgrade so I fully understand if there's breaking changes - just want to know what they are and what are the migration suggestions 🙇‍♂️

klimeryk added a commit to klimeryk/recalendar.js that referenced this issue Feb 10, 2023
Looksl like 3.* has issues with page sizes and layout:
diegomura/react-pdf#2006
renderer@2.3.0 and pdfkit@3.* is the best combination so far that is
still an upgrade, but does not break the layout completely for some
reason.
@aready87
Copy link

I believe "feat: variable dpi #1869" should be rolled back. Variable DPI should NOT be adjusting page size, but strictly image resolutions (the optional Resolution array %ALDImageResolution (see page 909 of PDF Reference 1.6).

The changes made in #1869 weren't properly tested before being merged. It broke how a pdf is supposed to be structured.

Ideally:
Images should be embedded as-is without adjustments (any compression) as default. If a user provides a dpi prop for a page, then the image's resolution gets adjusted accordingly.

@vidjuheffex
Copy link

any updates on this?

This was referenced Jun 2, 2024
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

Successfully merging a pull request may close this issue.

5 participants