PDF Joiner — Image to PDF page: size, DPI, margins
Every raster image goes into a PDF the same way: as an Image XObject scaled onto a page rectangle. The only real decision is what DPI to declare. That number controls whether a 4032×3024 photo lands neatly on A4 or sprawls across an imaginary 56-inch sheet.
What the file gives you
A raster image carries pixel dimensions and, optionally, a DPI value
in EXIF or a chunk like pHYs. It does not carry a physical size. Inches
and centimeters are derived: pixels / DPI.
What PDF expects
A PDF page has a physical size in points, where 72 points equal one inch. A4 portrait is 595×842 pt, or 8.27×11.69 inches. When you place a raster image on a page, the rectangle it occupies is:
width_pt = pixel_width / DPI × 72
height_pt = pixel_height / DPI × 72
A 4032×3024 photo at 72 DPI demands 4032×3024 pt of page real estate, which works out to 56×42 inches. The same photo at 300 DPI is 13.4×10.1 inches, still over A4. At 480 DPI it shrinks to roughly 8.4×6.3 inches and barely fits portrait A4.
Higher DPI means a smaller image on the page.
Picking a DPI
A reasonable algorithm starts at 150 DPI (photos look right at that size) and raises the value just enough to fit A4 with a small margin:
width_pt = pixels / 150 × 72
if width_pt > 595:
DPI = 150 × (width_pt / 595)
For a 4032×3024 iPhone photo, 150 DPI puts the width at 1934 pt, well
over the 595 pt limit. The algorithm bumps DPI to
150 × (1934 / 595) ≈ 487, which lands the image at 596 pt
wide, one pixel column off A4 portrait.
DPI is a label, not a property
A raster image has no intrinsic DPI. The number is a hint to the renderer telling it how many physical inches to stretch the pixel grid across. The same JPEG can describe itself as “300 DPI on A4” or “1200 DPI on a postage stamp” without a pixel changing.
In PDF this hint becomes a cm (concatenate matrix)
operator: a transformation matrix that scales the unit-square Image
XObject up to the page rectangle. Changing the matrix never touches the
compressed image data.
Orientation
If width exceeds height, a landscape page makes sense. Otherwise the image floats in a vertical strip with thick white bands above and below.
Picking orientation per image produces a PDF with mixed portrait and landscape pages, which every reader handles fine but which prints awkwardly. Forcing one orientation everywhere costs white space. Most combiners pick per-image and let the user override.
Margins
Edge-to-edge fills the page with the image and suits photo books. Margins of half an inch to an inch suit document-style PDFs that get bound or annotated. Edge-to-edge is the usual default.
Multiple images per page
Contact-sheet mode tiles thumbnails into a grid. It’s standard for photo printing services and rare in general-purpose combiners. Pick a grid (3×3, 4×6), compute the cell rectangle, place each thumbnail with margins.
What ends up in the PDF
A page with one image, internally:
- An Image XObject holding the compressed pixels (DCTDecode for JPEG sources, Flate for everything else).
- A page content stream with
q ... cm /Im0 Do Q: save state, apply transform, draw XObject, restore. - A resource dictionary mapping
/Im0to the XObject. - A MediaBox entry for the page size in points.
File size is governed by the compressed image, not by the page rectangle. Changing DPI rewrites the matrix and nothing else.
Defaults worth choosing carefully
- Base DPI: 150 or 200. Anything lower and small text in screenshots becomes unreadable.
- Max page size: A4 or Letter, depending on locale.
- Auto-orientation: on, with an option to disable for users who want a uniform stack.
- JPEG quality on re-encode: 75–85 for general use, 90+ when the user opts into high-quality.
- Strip EXIF/IPTC/XMP: on by default. PDFs aren’t the right place for camera metadata, and the bytes add up.