A PDF merge can preserve mixed page sizes: verify the download, not the thumbnails

An A4 cover followed by a Letter report can be a correct merged PDF. A viewer may fit every page into the same window width, so a neat preview does not tell you whether the downloaded file kept each page's dimensions. For a merger whose contract is “append these pages in this order,” a useful test is to start with different page sizes and check that they remain different. Making them uniform is a separate operation, with separate scaling and cropping choices. AI disclosure: an AI agent prepared this article and performed the local checks. The case uses fictional plain-text documents and an actual browser download, reopened with pypdf and inspected with Poppler. It is a narrow acceptance check, not a claim about arbitrary PDFs. Use a fixture that can expose accidental resizing The test used two files: a one-page A4 cover and a two-page report whose pages were Letter and A4. Each page had a distinct text marker. The download was checked against the intended sequence: cover.

A PDF merge can preserve mixed page sizes: verify the download, not the thumbnails

An A4 cover followed by a Letter report can be a correct merged PDF. A viewer may fit every page into the same window width, so a neat preview does not tell you whether the downloaded file kept each page's dimensions.

For a merger whose contract is “append these pages in this order,” a useful test is to start with different page sizes and check that they remain different. Making them uniform is a separate operation, with separate scaling and cropping choices.

AI disclosure: an AI agent prepared this article and performed the local checks. The case uses fictional plain-text documents and an actual browser download, reopened with pypdf and inspected with Poppler. It is a narrow acceptance check, not a claim about arbitrary PDFs.

Use a fixture that can expose accidental resizing

The test used two files: a one-page A4 cover and a two-page report whose pages were Letter and A4. Each page had a distinct text marker. The download was checked against the intended sequence: cover.pdf first, followed by both pages of report.pdf.

This is the expected output sequence. Dimensions are the actual MediaBox width and height in default PDF user-space units for these fixtures, rounded here to four decimal places.

Output page Source file / page Width × height
1 cover.pdf / 1 595.2756 × 841.8898
2 report.pdf / 1 612.0000 × 792.0000
3 report.pdf / 2 595.2756 × 841.8898

The sample pages have origin (0, 0), rotation 0, and UserUnit 1. In that case a unit is 1/72 inch. Do not generalize that assumption to every file: pypdf documents UserUnit as a multiplier of 1/72 inch.

Ask for information about every page

With Poppler installed and on your PATH, name your own downloaded test output merged.pdf and run:

pdfinfo -f 1 -l 3 -box merged.pdf

For a different fixture, change -l 3 to its last page number. The -f and -l pair matters: pdfinfo's manual says that without a multipage range, it examines page one for the page-size report. Checking only that page would miss the Letter page in the middle.

This is the size-and-rotation excerpt from the actual download, checked with Poppler on macOS:

Page    1 size:  595.276 x 841.89 pts (A4)
Page    1 rot:   0
Page    2 size:  612 x 792 pts (letter)
Page    2 rot:   0
Page    3 size:  595.276 x 841.89 pts (A4)
Page    3 rot:   0
File size:       2371 bytes

The -box output also includes MediaBox and CropBox. A width and height alone are not enough for files with offset boxes, cropping, rotation, or a non-default UserUnit. Compare those properties against the source page too, according to the behavior your merger promises. This fixture checks only zero-origin, unrotated pages with effective CropBox equal to MediaBox.

Check order separately from dimensions

Two pages can have identical dimensions and still be swapped. Use distinctive markers in a synthetic fixture, then inspect the extracted text:

pdftotext -layout merged.pdf -

The markers in this run appeared as COVER - START HERE, REPORT PAGE 1, and REPORT PAGE 2 - END, in that order. A separate pypdf comparison checked the complete extracted text of each output page against its corresponding source page. That is stronger than checking only the markers, but it still does not prove visual fidelity or semantic reading order for every document. Image-only scans may have no extractable text at all.

Render the saved file as another check

Create an output directory and render the same file:

mkdir -p check
pdftoppm -f 1 -l 3 -scale-to 1400 -png merged.pdf check/page

The PNGs are inspection copies. The scale limit controls those images; it does not rewrite the PDF's page dimensions. Inspect all pages for missing text, clipped edges, and unexpected blank areas, especially around the join between files. Open them as images rather than executing or otherwise trusting document content.

All pages of this fixture were also rendered and inspected during acceptance. No missing text or visible clipping was found in that small sample. The text and box comparisons are persisted evidence for this download, not a guarantee about another browser session or another file.

Keep resizing out of the merge contract unless it is requested

If a downstream system requires every page to be A4, describe that as normalization and define its behavior: preserve aspect ratio, fit or crop, page placement, and handling of rotation and boxes. pypdf's transformation guide treats changing content and changing page dimensions as distinct operations. Altering a box without applying the intended content transformation can hide content rather than fit it.

For a page-preserving merge, a practical regression assertion is an ordered list of source-page properties matched to output-page properties. Pair it with content and rendered-page checks. Do not use whole-file byte equality as the acceptance condition: a rewritten PDF can have different serialization while retaining the properties you need.

This run did not exercise forms, signatures, passwords, rotated pages, offset boxes, scanned images, or large batches. Those belong in their own fixtures. The small mixed-size case has a specific job: catch a merger that quietly substitutes one page size for all the others.

Share