PDF page boxes
A PDF page can carry up to five rectangles that describe different things about the same sheet: the physical medium, the region a viewer shows, the area a press images, the finished size after trimming, and the extent of the content. They are the data behind every conversation about bleed and trim, and most "the PDF is the wrong size" problems are one of them set to a value nobody expected. This page gives the definitions from ISO 32000-1, the defaults and inheritance rules that decide what a missing box means, and the commands to inspect and set them.
The five boxes#
Each box is an entry in the page dictionary holding a rectangle in default user space units, which are points (1/72 in) unless the page sets /UserUnit. The meanings below paraphrase ISO 32000-1 §14.11.2.1 and Table 30.
| Key | Status | Default | Defines | Mainly used by |
|---|---|---|---|---|
/MediaBox | required, inheritable | none | The boundaries of the physical medium: the sheet, including any area for bleed, printer's marks or unprintable margins. Content outside it may be discarded. | Everything; it is the only box that must exist |
/CropBox | optional, inheritable | MediaBox | The region to which content is clipped when displayed or printed. It has no meaning in terms of physical geometry; it only says what to show. | Viewers, desktop printing |
/BleedBox | optional, PDF 1.3 | CropBox | The region to which content is clipped in a production environment, including extra bleed to absorb cutting and folding tolerances. | Prepress RIPs, imposition |
/TrimBox | optional, PDF 1.3 | CropBox | The intended dimensions of the finished page after trimming. | Prepress, imposition, preflight |
/ArtBox | optional, PDF 1.3 | CropBox | The extent of the page's meaningful content, including intended white space, as the creator intended. | Placing a page inside another document |
The specification also describes, as notes, how the boxes are used in four situations. Printing a finished page on a desktop printer uses the media box as advice for selecting paper and expects the crop and trim boxes to equal it. Printing an intermediate page for a prepress process images the bleed box and positions the content by the trim box, generating cut marks outside the bleed box. Imposing many pages on a press sheet does the same per page. Placing a page in another application uses the art box, clipped to either the art box or the bleed box depending on the convention in use. Readers that act on bleed, trim and art boxes typically do so by adjusting the crop box, which is why a viewer shows what a RIP will print only when someone has set the crop box to match.
Rectangles and units#
A rectangle is an array of four numbers, conventionally [llx lly urx ury]: the lower-left and upper-right corners (§7.9.5). The standard allows any two diagonally opposite corners, so a well-behaved reader normalises the array before using it; a box written as [612.28 858.9 0 0] is legal and describes the same page. Values are real numbers, not integers, and A4 in points is not a round number: 210 mm is 595.276 pt and 297 mm is 841.890 pt. Most libraries write two decimals. The units reference has the conversion table.
Boxes need not start at the origin. A trim box of [8.504 8.504 603.780 850.394] is perfectly ordinary; it means the finished page begins 8.504 pt in from the media box's lower-left corner. Negative coordinates are allowed too, and some generators place the trim box at [0 0 w h] and let the media box extend into negative space for the bleed.
/UserUnit (PDF 1.6, optional) scales the unit for the whole page: a value of 2 means each user space unit is 2/72 in. It exists so that very large drawings can exceed the 14,400-unit implementation limit on page dimensions, and it is rare outside engineering workflows. Tools that report page size in millimetres must multiply by it, and several do not.
Defaults and inheritance#
Two different mechanisms fill in a missing box, and they are easy to confuse.
The first is the default value in Table 30: a missing /CropBox means "same as the media box", and a missing /BleedBox, /TrimBox or /ArtBox means "same as the crop box". So a page that has only a media box has all five boxes equal to it, and a page with media and trim boxes but no bleed box has a bleed box equal to the crop box, which is the media box. That last case is the one that catches people: setting a trim box without a bleed box makes the bleed box the whole sheet.
The second is inheritance from the page tree (§7.7.3.4). /MediaBox, /CropBox, /Rotate and /Resources are marked inheritable in Table 30: if a page object lacks the entry, the reader walks up through /Parent links and uses the first value it finds. A document that sets /MediaBox once on the root /Pages node has given every page that size, and an individual page can still override it. /BleedBox, /TrimBox and /ArtBox are not inheritable, which means a trim box set on a page tree node is ignored; it must be on each page. Linearized files are required to write every attribute on every page and never rely on inheritance.
If a crop, bleed, trim or art box extends beyond the media box, it is reduced to its intersection with the media box (§14.11.2.1). Readers do this silently.
Rotation and reported size#
/Rotate (inheritable, default 0, a multiple of 90) says how many degrees clockwise the page is turned when displayed or printed. The boxes are stored in unrotated user space, so a landscape page produced by rotating an A4 portrait page has /MediaBox [0 0 595.28 841.89] /Rotate 90, and tools disagree about what its "width" is. A viewer, pdf.js's viewport, and pdfcpu boxes list (which prints rot=+90 and the orientation) report 841.89 × 595.28; pypdf's page.mediabox.width and pdf-lib's getWidth() report the stored 595.28. When a size check matters, read /Rotate as well as the box, and say which convention you used.
A genuinely landscape page has a landscape media box and /Rotate 0. Both representations print the same; they differ in what the coordinates of the content mean, which matters when stamping, imposing or placing pages programmatically.
What the standards require#
PDF/X, the family of ISO 15930 standards for print exchange, turns the optional boxes into requirements. According to the public summaries, a PDF/X file must have a media box, must define the printable extent with either a trim box or an art box, and if it will be printed with bleed must define a bleed box that is larger than the trim or art box and no larger than the media box. Preflight tools check these rules first, and "missing TrimBox" is the most common PDF/X failure in files exported with default settings. The standards page covers PDF/X parts and conformance levels; the bleed page covers what printers expect from the numbers.
A4 with 3 mm bleed, exactly#
Working the numbers once shows how the boxes relate. A4 is 210 × 297 mm; 3 mm bleed on every side makes the sheet 216 × 303 mm. In points, dividing millimetres by 25.4 and multiplying by 72:
- 3 mm
- 3 ÷ 25.4 × 72 = 8.504 pt
- 210 × 297 mm
- 595.276 × 841.890 pt
- 216 × 303 mm
- 612.283 × 858.898 pt
The page dictionary then carries:
<< /Type /Page
/MediaBox [0 0 612.283 858.898]
/BleedBox [0 0 612.283 858.898]
/TrimBox [8.504 8.504 603.780 850.394]
/ArtBox [8.504 8.504 603.780 850.394]
...
>>The bleed box equals the media box here because this sheet has no printer's marks; a file with crop marks would have a larger media box and the bleed box as shown. Rounding the values to two decimals (612.28, 858.9, 8.5, 603.78, 850.39) is normal and harmless at print resolution; what matters is that the trim box is exactly 595.276 × 841.890 and centred. The bleed calculator produces these arrays for any trim size and bleed.
Inspecting boxes#
The quickest overview is pdfcpu, which prints every box for every page, flags which are inherited or defaulted, and reports rotation:
pdfcpu boxes list file.pdf
# Page 1: rot=+0 orientation:portrait
# MediaBox (points) (0.00, 0.00, 612.28, 858.90) w=612.28 h=858.90 ar=0.71
# CropBox (points) (0.00, 0.00, 612.28, 858.90) w=612.28 h=858.90 ar=0.71 (default)
# TrimBox (points) (8.50, 8.50, 603.78, 850.39) w=595.28 h=841.89 ar=0.71
# ...
# only media and crop boxes of page 1, in centimetres
pdfcpu boxes list 'm,c' file.pdf --pages 1 --unit cmWith qpdf, ask for the page objects in JSON and then print the one you want; with mutool, address the page by path:
qpdf --json --json-key=pages file.pdf # lists "object": "3 0 R" for each page
qpdf --show-object=3 file.pdf # the page dictionary, boxes included
mutool show file.pdf pages/1 # same page by positionIn code, pypdf exposes each box as a RectangleObject with left, bottom, right, top properties, and pdf-lib returns { x, y, width, height } objects:
from pypdf import PdfReader
page = PdfReader("file.pdf").pages[0]
for name in ("mediabox", "cropbox", "bleedbox", "trimbox", "artbox"):
box = getattr(page, name)
print(f"{name:9} {float(box.left):8.3f} {float(box.bottom):8.3f} "
f"{float(box.right):8.3f} {float(box.top):8.3f}")
print("rotate", page.rotation)import { readFileSync } from "node:fs";
import { PDFDocument } from "pdf-lib";
const doc = await PDFDocument.load(readFileSync("file.pdf"));
const page = doc.getPage(0);
console.log("media", page.getMediaBox()); // { x, y, width, height } in points
console.log("trim", page.getTrimBox()); // falls back to crop, then media, per the defaults
console.log("rotation", page.getRotation().angle);pypdf reports a missing box as equal to its default, which mirrors what a reader does; it does not tell you whether the entry was present. To know that, look at the raw dictionary (page.get("/TrimBox") returns None when absent), or use the PDF inspector, which marks each box as explicit, inherited or defaulted.
Setting boxes#
pdfcpu's boxes add takes a description string: a box name, a colon, and either an absolute rectangle in user space, a margin inside the parent box, or the name of another box to copy:
# absolute trim box, and a bleed box equal to it, on page 2 only
pdfcpu boxes add 'trim:[8.504 8.504 603.78 850.394], bleed:trim' in.pdf out.pdf --pages 2
# crop box 1 inch inside the media box; bleed 15% inside crop; art and trim copy bleed
pdfcpu boxes add 'c:1, b:15%, a:b, t:b' in.pdf out.pdf -u inchespdf-lib's setters take x, y, width, height, not the llx lly urx ury of the stored array, so the A4 example becomes:
page.setMediaBox(0, 0, 612.283, 858.898);
page.setBleedBox(0, 0, 612.283, 858.898);
page.setTrimBox(8.504, 8.504, 595.276, 841.890); // x, y, width, height
page.setArtBox(8.504, 8.504, 595.276, 841.890);And pypdf assigns a RectangleObject built from the four corner coordinates:
from pypdf import PdfReader, PdfWriter
from pypdf.generic import RectangleObject
writer = PdfWriter(clone_from=PdfReader("in.pdf"))
for page in writer.pages:
page.mediabox = RectangleObject((0, 0, 612.283, 858.898))
page.bleedbox = RectangleObject((0, 0, 612.283, 858.898))
page.trimbox = RectangleObject((8.504, 8.504, 603.780, 850.394))
page.artbox = page.trimbox
writer.write("out.pdf")Whichever tool you use, check the result with pdfcpu boxes list or the inspector afterwards. The failure that survives silent conversions is a trim box that is correct but not centred in the media box, which prints with uneven bleed on one side.
Sources
- ISO 32000-1:2008, §14.11.2 Page boundaries PDF 1.7, distributed free of charge by Adobe
- ISO 32000-1:2008, Table 30 Entries in a page object; §7.7.3.4 Inheritance of page attributes; §7.9.5 Rectangles
- PDF/X (Wikipedia), summary of the ISO 15930 page-box requirements ISO 15930 itself is paywalled; only public summaries were consulted
- pdfcpu documentation, boxes list and boxes add
- pdf-lib API, PDFPage
- pypdf documentation, cropping and transforming
- qpdf manual, command-line options