PDFPipe

ISO A series / A4

A4 page size for PDF generation

A4 is the default page for business documents everywhere except North America, and the default this API uses when no format is given.

The dimensions

One measurement in four units. Millimetres and inches are what a printer works in; points are what the PDF itself stores; pixels are only useful for checking a screen mock-up against the real thing.

  • Millimetres: 210 x 297 mm
  • Inches: 8.27 x 11.69 in
  • Points: 595 x 842 pt
  • CSS pixels: 794 x 1123 px at 96 dpi

Where the size comes from

The A series is built on one rule: halving a sheet across its long side gives the next size down with the same proportions. That only works if the ratio of the sides is the square root of two, and A0 is defined as the sheet of that shape with an area of exactly one square metre. A4 is A0 folded in half four times, which is where 210 by 297 comes from. Nothing about it is arbitrary, and it is why an A5 booklet imposes onto A4 with no scaling.

What gets printed at this size

  • invoices, statements and anything a finance team will file
  • contracts and reports, which is most of what an API like this renders
  • letters, in every country that did not standardise on Letter

Margins that survive a real printer

18mm top and bottom, 16mm left and right is a safe starting point. Office laser printers cannot print within about 5mm of any edge and many cannot manage the bottom 10mm, so anything tighter than 10mm risks being clipped by the machine rather than by your layout. If the document will be hole punched, widen the left margin to 25mm and leave the right at 16mm.

The CSS

A4 is one of the six named formats the render API accepts, so it can be set in the request options or in the document's own CSS. Setting it in CSS keeps the size with the template, which is usually what you want.

css
@page {
  size: A4 portrait;
  margin: 18mm 16mm;
}

/* The browser default body margin is 8px and it stacks on top of the
   page margin, which is why margins so often come out larger than set. */
html,
body {
  margin: 0;
  padding: 0;
}

The render request

With a named format the size travels in the options and the CSS is optional.

json
{
  "html": "<!doctype html>...",
  "options": {
    "format": "A4",
    "margin": { "top": "18mm", "bottom": "18mm", "left": "16mm", "right": "16mm" }
  }
}

The mistake people make

Designing at 1123px because that is what A4 is at 96 pixels to the inch, then discovering the layout breaks when the same HTML is rendered at a different scale. Lay out in millimetres and let the page box do the conversion.

Frequently asked

What is A4 in pixels?

794 x 1123 px at 96 dpi, at the 96 pixels to the inch that CSS assumes. That number is useful for comparing a screen mock-up against the page, and useless for laying out the document: use 210 x 297 mm instead, because a page laid out in pixels shifts whenever the render scale changes.

Can I pass A4 as a format?

Yes. "A4" is one of the six format values the API accepts, alongside A4, A3, A5, Letter, Legal and Tabloid.

Does landscape need a different page size?

No. Landscape is the same rectangle turned, so it is set as an orientation rather than as swapped dimensions. Writing the width and height the other way round produces the same page and makes the intent harder to read later.

Other page sizes

Sizes that come up in the same conversation, and one from each of the other families.

Paste the CSS below into the playground and see the page box it produces.