Stacked linear / PDF417
PDF417 barcode in a PDF
A stack of short linear rows rather than a matrix: high capacity, a wide flat shape, and the symbology behind driving licences and boarding passes.
Where the symbol comes from
This API renders HTML to PDF. It does not generate barcodes, so the PDF417 symbol itself is produced by an encoder in your own stack and placed in the markup, either as inline SVG or as a data URI. That split matters more than it sounds: the encoders are mature and correct, and almost every barcode that will not scan failed for a layout reason rather than an encoding one. Everything below is about the layout half.
What it can encode
Up to roughly 1,850 text characters, 2,710 digits or 1,100 bytes in a single symbol, depending on the compaction mode the encoder picks. The name comes from the structure: each codeword is 17 modules wide, made of four bars and four spaces.
The check digit, and who computes it
Error correction rather than a check digit, at nine selectable levels from 0 to 8. Higher levels add codewords and recover more damage. Level 5 is a common default for a document that will be handled; a symbol on a card that gets carried in a wallet justifies more.
Size and quiet zone
The two measurements that decide whether a scanner accepts the symbol, and the two most often lost when a design is adjusted to fit.
- X-dimension: The module width, commonly 0.25mm or above, with a row height of at least three times the module width. The aspect ratio is chosen by the encoder from a target number of columns, so the same data can be a wide short symbol or a narrow tall one.
- Quiet zone: 2 modules on all four sides, which is small compared with a linear symbology and is still frequently omitted. A PDF417 laid flush against a printed rule fails.
Where it is used
- driving licences and identity documents, where the symbol carries the whole record
- airline boarding passes, in the format the industry standard defines
- shipping labels where a large payload has to travel with the parcel
- any application that has to work offline, because the data is in the symbol rather than behind a lookup
Placing it in the markup
The quiet zone is padding on the container rather than part of the encoder's output, so it survives a change of encoder. Dimensions are in millimetres, because a bar width is a physical measurement and a percentage makes it depend on whatever the container happens to be.
<figure class="pdf417">
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0i..." alt="Boarding pass data">
</figure>
<style>
.pdf417 {
margin: 0;
/* 2 modules of quiet zone on all four sides. Small, and still the
thing most often left out because the symbol looks finished. */
padding: 1.5mm;
background: #fff;
width: max-content;
print-color-adjust: exact;
-webkit-print-color-adjust: exact;
}
.pdf417 img {
/* Absolute width AND height. A stacked symbology has a row height
that matters as much as the module width, and letting one be auto
while the other is fixed distorts the aspect. */
width: 76mm;
height: 23mm;
display: block;
image-rendering: crisp-edges;
}
</style>What goes wrong on paper
Letting the aspect ratio drift. PDF417 rows have a defined height relative to the module width, and a symbol squashed vertically to fit a strip on a boarding pass loses the row separation the decoder relies on. Set both dimensions, and if the symbol does not fit, re-encode it with a different column count rather than scaling what you have.
First thing to check when it will not scan
Check whether the symbol was rasterised. PDF417 has fine horizontal structure, and a bitmap resampled at print resolution merges adjacent rows in a way that looks fine at a glance and destroys the decode. Encode to SVG and let the PDF carry it as vector.
Vector, not a bitmap
Encode to SVG wherever the encoder offers it. A rasterised barcode is resampled when the PDF is printed, and at 203 or 300 dots per inch the bar edges land between printer dots, so the ratio of bar to space drifts by a fraction of a millimetre. That fraction is the whole tolerance. An SVG stays vector inside the PDF and is rendered at the printer's own resolution, which removes the entire failure mode. Where a bitmap is unavoidable, generate it at the final physical size and set image-rendering so nothing smooths the edges.
Frequently asked
Does this API generate PDF417 symbols?
No. It renders HTML to PDF. The symbol is produced by a barcode library in your own application and embedded in the markup as SVG or as a data URI, which is the same way you would put any other generated graphic into a document. What this API is responsible for is that the symbol reaches the page at the size and position you specified.
Why does it scan on screen and fail on paper?
Three reasons, in order of frequency. The quiet zone is present on screen because the browser window is white and absent on paper because the label is not. The symbol was sized as a percentage, so it came out at a different physical width than the one that was tested. Or it is a bitmap, and printing resampled it so the bar-to-space ratio moved outside tolerance.
Can I scale the symbol to fit the space I have?
Uniformly, within the range the symbology allows, and never on one axis. The module width, commonly 0.25mm or above, with a row height of at least three times the module width. The aspect ratio is chosen by the encoder from a target number of columns, so the same data can be a wide short symbol or a narrow tall one. is the constraint on the way down. Scaling one axis changes the bar-to-space ratio on a linear symbology and makes a 2D symbol non-square, and neither survives a scanner.
Other symbologies
Codes of the same kind, and one from each of the other kinds.
Code 128 barcode in a PDF
The general-purpose linear barcode: full ASCII, any length, and the densest of the common linear symbologies for numeric data.
QR code in a PDF
The 2D code everyone recognises: read by any phone, generous error correction, and a quiet zone four modules wide that almost nobody leaves.
Every symbology, with its quiet zone
The full list, grouped by whether the code is linear, stacked or a matrix.
4x6 shipping label PDF size
The label most of these end up on, with the margins and the quiet zone advice.
Event ticket HTML template
A complete template with a code sized in absolute units and its quiet zone in place.
Paste the markup into the playground with your own encoder's output and see what comes out at the real page size.