PDFPipe

2D matrix / Data Matrix

Data Matrix code in a PDF

The small-format 2D code: a one module quiet zone, an L-shaped finder, and the symbology of choice when there is almost no room.

Where the symbol comes from

This API renders HTML to PDF. It does not generate barcodes, so the Data Matrix 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 3,116 digits or 2,335 alphanumeric characters in the largest ECC 200 symbol. Symbols can be square or rectangular, and the rectangular forms exist specifically for marking things that are long and thin, such as a cable or a component lead.

The check digit, and who computes it

Reed-Solomon, in the ECC 200 version that is what anyone means by Data Matrix today. Unlike QR the correction level is not selectable: it is fixed by the symbol size, which removes a decision and removes a way to get it wrong.

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: Down to about 0.25mm for a printed label, and considerably smaller for direct part marking where the symbol is etched rather than printed. The small end is where Data Matrix beats QR, and the reason is the quiet zone rather than the data density.
  • Quiet zone: 1 module on all four sides. That is the distinguishing property. A QR code needs four modules of blank space and a Data Matrix needs one, so on a component the size of a fingernail the Data Matrix wins before either has encoded anything.

Where it is used

  • pharmaceutical serialisation, where a GS1 Data Matrix carries product, batch, expiry and serial on every pack
  • electronic components and direct part marking, where the symbol is etched onto the part
  • small labels and vials in laboratory and clinical settings
  • postal applications in several national systems

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.

html
<figure class="dmtx">
  <img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0i..." alt="GS1 Data Matrix">
  <figcaption>(01)05012345678900(17)271130(10)A4471(21)88213</figcaption>
</figure>

<style>
.dmtx {
  margin: 0;
  /* One module. On a 22mm symbol of 22 modules that is 1mm. The
     temptation on a crowded label is to make it zero, and zero is the
     one value that does not work. */
  padding: 1mm;
  background: #fff;
  width: max-content;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}
.dmtx img {
  width: 22mm;
  height: 22mm;
  display: block;
  image-rendering: crisp-edges;
}
.dmtx figcaption {
  font: 7pt/1.25 "IBM Plex Mono", monospace;
  margin-top: 1.2mm;
  max-width: 24mm;
  word-break: break-all;
}
</style>

What goes wrong on paper

Printing it small enough that a module falls below the printer's dot pitch. At 203 dots per inch a dot is 0.125mm, so a 0.25mm module is two dots and any rounding is a 50 percent error on that module. Data Matrix tolerates a lot, and it does not tolerate a module that the printer cannot represent. Work out the module size in dots before choosing the symbol size.

First thing to check when it will not scan

Check the finder pattern is intact: two solid adjacent edges forming an L, and two edges of alternating modules opposite them. Damage or a crop that clips one of those four edges makes the symbol unlocatable, and it is a crop that a designer would not think of as damage.

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 Data Matrix 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. Down to about 0.25mm for a printed label, and considerably smaller for direct part marking where the symbol is etched rather than printed. The small end is where Data Matrix beats QR, and the reason is the quiet zone rather than the data density. 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.

Paste the markup into the playground with your own encoder's output and see what comes out at the real page size.