Skip to content

How do I create PDFs at the right page size? #3

Closed

Description

@lhr0909

Hi,

I am checking in after doing integration with the library. So far it is working very well, and we could render very high quality PDFs, which is great!

When we were checking the size of the PDF (width and height), and found that it was way larger than what it was set at render time (A4). We are looking at a number that is almost like a A0 size from MacOS preview.

We found this issue when we were trying to merge existing PDFs together and found that our renders were way larger than A4s.

I am sending an example output from our code:

        let document = PDFViewKit.PDFDocument {
            ReceiptPDFContentView(
                data: exportData,
                attachmentImage: attachmentImage,
                hasPDFAttachment: isPDFAttachment
            )
        }

        try await MainActor.run {
            try PDFRenderer.render(
                document: document,
                to: destinationURL,
                atPageSize: DIN.a4
            )
        }
Image Image

We now had to scale the attached PDF to make it look right, so it is less than ideal, but not the end of the world.

Please advice if there is a better way to render it. I have been checking the lib source code and we were not wrapping our content view with PDFPage and I am not sure if we need to in order to control the output size. Cheers!

Activity

  1. sgade commented on Nov 30, 2025

    @sgade
    Owner

    Hej Simon, what OS are you running this on? I assume iOS? Maybe the display DPI is different than 96 DPI by default and could produce a wrong scaling factor. This might be relevant on macOS as well.

    See the default assumption here.

    If you could try, please adjust the DPI for your device and report if we might need to change how the base DPI is calculated.

  2. lhr0909 commented on Nov 30, 2025

    @lhr0909
    ContributorAuthor

    I have been testing with iPhone 16 Pro Max. How can we change the DPI for the device or for PDFViewKit?

  3. sgade commented on Dec 1, 2025

    @sgade
    Owner

    You could try to modify the source line I linked and, for testing, change the value of .display to something that matches the DPI of your device. If that brings the output more in-line with the expected size, then we have identified the culprit.

  4. lhr0909 commented on Dec 2, 2025

    @lhr0909
    ContributorAuthor

    @sgade Got it! We will try to modify the DPI for display scaling and verify if this is the culprit. The device I am testing seems to have 466 ppi. So we will see if this is the DPI we need to set to.

    I am currently on vacation so I will update here a little later! Happy holidays and New Year to you too! Cheers!

  5. sgade commented on Jun 2, 2026

    @sgade
    Owner

    Hej @lhr0909, did you have the time to test this? Please feel free to share your findings.

    I'd like to improve the library for all users if possible, and at least add some clarifying documentation.

  6. lhr0909 commented on Jun 2, 2026

    @lhr0909
    ContributorAuthor

    Hey @sgade I haven't gotten enough time to test more closely after I got it to work by scaling the attached pdf document to match the large size. Let me know if you have any idea for a quick check / fix or if you need a minimal reproduction of this issue on my end. Thanks!

  7. sgade commented on Jun 2, 2026

    @sgade
    Owner

    Would love to get some minimum example that can reproduce the behavior you experienced.

    I'd run that on my 16 Pro as well to get a comparison.
    I guess that would be a great baseline for exploration together with your data.

  8. lhr0909 commented on Jun 3, 2026

    @lhr0909
    ContributorAuthor

    @sgade I did some exploration and I think I found the root cause. Let me know if #4 is something you would want to test and merge. Meanwhile I will see how I can get a reproduction repository for the issue. Cheers!

  9. sgade commented on Jun 3, 2026

    @sgade
    Owner

    Thanks for taking the time to investigate and create the PR. There is no reason for you to create another repo as well.

    I'll take a close look as soon as possible but from what I have glanced it looks promising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions