PDFPipe

Receipt rolls / 58mm receipt roll

58mm thermal receipt PDF size and page setup

The 58mm roll is the narrow receipt used by mobile and handheld printers, with a printable width of roughly 48mm.

Where the size comes from

58mm exists because the printer has to fit in a hand or a belt holster. At 203 dots per inch the common head is 384 dots, which is 48.1mm, so a full third of the media width is feed margin. It is the tightest commonly used page in this list and the one where layout decisions are forced rather than chosen.

What gets printed at this size

  • mobile card readers and handheld point of sale
  • taxi, delivery and field service receipts
  • parking and vending tickets

Margins that survive a real printer

2mm left and right for a 54mm page box, and design to 48mm of content. At 48mm a monospace face at 9pt fits about 32 characters, which is the number that actually governs the layout: an item name and a price on the same line means the name gets around 22 characters and no more.

The CSS

58mm receipt roll is not one of the six named formats the API accepts, so the size has to come from the document. Declare it in the page box and set prefer_css_page_size in the request.

css
@page {
  size: 58mm 200mm;
  margin: 0 2mm;
}

body {
  margin: 0;
  font-family: "IBM Plex Mono", "Courier New", monospace;
  font-size: 9pt;
  color: #000;
}

.line {
  display: flex;
  justify-content: space-between;
  gap: 2mm;
}

.line .name {
  /* 32 characters total, and the price needs ten of them. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

The render request

With a custom size the options carry no format at all: the one flag tells the renderer to use the page box the document declares.

json
{
  "html": "<!doctype html>...",
  "options": {
    // No named format. The page box in the document's own CSS is the
    // size, and this flag is what tells the renderer to use it.
    "prefer_css_page_size": true
  }
}

The mistake people make

Porting an 80mm receipt template by changing the page size. The content width drops by a third, every item line wraps, and a receipt that was twelve lines becomes twenty-five. The 58mm layout has to drop columns, not shrink them.

Frequently asked

How do I set a size the API has no name for?

Declare the rectangle in the document's own CSS page box, in millimetres or inches, and set prefer_css_page_size on the request. Do not also pass a named format: the two disagree and you should not have to know which wins.

Can I pass 58mm receipt roll as a format?

No. The API accepts six named formats: A4, A3, A5, Letter, Legal and Tabloid. 58mm receipt roll is reached through the document's page box with prefer_css_page_size set, which is a supported path and not a workaround.

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.