Why PDF Page Sizes Never Match What Users Expect
One of the easiest ways to make a PDF tool look broken is to merge documents with different page dimensions.
The operation succeeds.
The output opens.
But suddenly, some pages are larger than others.
Users usually blame the merge tool.
Sometimes they are right. Sometimes the source PDFs were already inconsistent.
A4 is not Letter
The first problem is that people use different page standards.
Here are three common sizes:
Paper
Dimensions in mm
A4
210 × 297
US Letter
215.9 × 279.4
US Legal
215.9 × 355.6
They look similar on screen, especially when zoomed out.
But their proportions are different.
If you combine A4 and Letter documents without handling their dimensions, you should not expect every page to line up perfectly.
PDFs have more than one page boundary
This is where things get interesting.
A PDF page can have several boundary boxes:
MediaBox: The physical extent of the page.
CropBox: The visible region normally shown or printed.
TrimBox: The intended finished page size for print production.
BleedBox: The area including extra space for printing bleed.
ArtBox: The meaningful content area.
These boxes can have different values.
For example, a PDF might have an A4 MediaBox but a smaller CropBox.
A viewer may display only the cropped region, while a tool reading the MediaBox sees the larger page.
That difference can produce unexpected output dimensions.
Rotation makes it more confusing
A page can have a rotation value of 90, 180, or 270 degrees.
A portrait page may therefore appear in landscape orientation without its underlying page dimensions being swapped.
If your code ignores rotation, calculations based only on width and height can produce incorrect results.
You need to consider both the page boxes and its rotation when calculating the displayed dimensions.
The scanned PDF problem
Scanned documents introduce another layer.
A scanner or conversion engine may create pages using pixel dimensions converted into PDF points.
For example, a 794 × 1123 pixel page at approximately 96 DPI corresponds to roughly 595 × 842 PDF points.
That is close to A4.
The important detail is that pixels and PDF points are different units.
One PDF point equals 1/72 of an inch.
A page that looks like an ordinary A4 scan may therefore have dimensions that surprise a developer expecting pixel-based values.
Why merging creates inconsistent dimensions
Imagine merging:
A4 invoices.
US Letter contracts.
A scanned document with custom dimensions.
A landscape spreadsheet.
A basic merge operation preserves the original page dimensions.
That is often the correct behaviour. Automatically resizing everything can distort content or make text harder to read.
But some tools need a consistent output size.
In those cases, I prefer normalising page dimensions during import, with explicit rules for scaling and positioning.
A useful implementation setting might look like this:
This is a configuration sketch, not a built-in pdf-lib option. The actual implementation needs to calculate the source page bounds and apply the required scaling and translation.
The real lesson
PDF dimensions are not just width and height.
They involve units, page boxes, rotation, and sometimes unusual source data.
If a merge tool ignores those details, inconsistent output is almost guaranteed.
I handle these document issues in my browser-based tools at pocketpdf.site.
4.
Top comments (0)