Linear (1D) / GS1-128
GS1-128 barcode in a PDF
Code 128 with a data structure on top: a function character marks the symbol as GS1, and the content is a sequence of Application Identifiers.
Where the symbol comes from
This API renders HTML to PDF. It does not generate barcodes, so the GS1-128 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
The same character set as Code 128, but the data is structured. An FNC1 in the first position tells the scanner this is GS1 data, and the content is then a run of Application Identifiers with their values: (00) is a serial shipping container code, (01) a trade item number, (10) a batch or lot, (17) an expiry date, (21) a serial number. The GS1 specification caps a single symbol at 48 data characters, which is the constraint that most often forces a second symbol.
The check digit, and who computes it
Two separate things, and confusing them is the classic error. The symbol carries the same modulo 103 check character as Code 128, computed by the encoder. Separately, the data inside some Application Identifiers has its own check digit: a GTIN in AI (01) ends with a modulo 10 check that is part of your data and that you must supply correctly.
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: 0.25mm to 1.016mm depending on where the label goes. A carton read by a fixed scanner on a conveyor needs the larger end of that range; a label read by hand can use the smaller.
- Quiet zone: 10 times the X-dimension at each end. On a logistics label the standard layout gives the symbol its own band across the label, which is partly to guarantee that space.
Where it is used
- logistics unit labels, where AI (00) carries the serial shipping container code
- pharmaceutical and food traceability, carrying batch and expiry alongside the item number
- variable measure retail products, where the weight is part of the encoded data
- any supply chain where a trading partner has specified GS1 rather than free-form
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.
<!-- Human-readable interpretation shows the AIs in brackets. The
brackets are NOT encoded in the symbol: they are punctuation for a
person, and an encoder that puts them in the data is wrong. -->
<figure class="gs1-symbol">
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0i..." alt="GS1-128">
<figcaption>(01)05012345678900(10)A4471(17)271130</figcaption>
</figure>
<style>
.gs1-symbol {
margin: 0;
padding: 0 8mm;
}
.gs1-symbol img {
width: 90mm;
/* Bar height matters here: a symbol read on a moving conveyor needs
enough height for the scan line to cross it at an angle. */
height: 32mm;
display: block;
}
.gs1-symbol figcaption {
font: 9pt/1.3 "IBM Plex Mono", monospace;
margin-top: 1.5mm;
/* The interpretation must be under the symbol and must be readable.
It is what a person falls back to, and on a pharmaceutical label it
is what a regulator expects to see. */
word-break: break-all;
}
</style>What goes wrong on paper
Encoding the brackets. The human-readable line shows AIs in parentheses so a person can parse it, and those parentheses are not part of the encoded data. A symbol containing literal brackets scans and then fails validation at the receiving end, which is a far more expensive failure than one that does not scan at all.
First thing to check when it will not scan
Check whether the symbol actually starts with FNC1. Without it the scanner reads plain Code 128 and hands the receiving system a string of digits with no structure, which usually presents as data being rejected rather than as a failed scan.
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 GS1-128 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. 0.25mm to 1.016mm depending on where the label goes. A carton read by a fixed scanner on a conveyor needs the larger end of that range; a label read by hand can use the smaller. 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.
EAN-13 barcode in a PDF: sizing and quiet zones
The retail barcode used everywhere outside North America: thirteen digits, a fixed size range, and an asymmetric quiet zone.
UPC-A barcode in a PDF
The North American retail barcode: twelve digits, and technically a subset of EAN-13 with a leading zero.
ITF-14 barcode in a PDF
The barcode printed on shipping cases: fourteen digits, deliberately coarse, and framed by bearer bars that exist to prevent misreads.
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.
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.