|
1 | | -`codext` can generate and read matrix barcodes. The `aztec`, `datamatrix` and `qr` codecs produce real, scannable Aztec, Data Matrix and QR codes (with Reed-Solomon error correction), while `fakeqr` only mimics the aspect of a QR code, hiding the input in an image that is not a valid one. |
| 1 | +`codext` can generate and read matrix and stacked barcodes. The `aztec`, `datamatrix`, `pdf417` and `qr` codecs produce real, scannable Aztec, Data Matrix, PDF417 and QR codes (with Reed-Solomon error correction), while `fakeqr` only mimics the aspect of a QR code, hiding the input in an image that is not a valid one. |
2 | 2 |
|
3 | 3 | ----- |
4 | 4 |
|
@@ -115,6 +115,30 @@ b'this is a test' |
115 | 115 |
|
116 | 116 | ----- |
117 | 117 |
|
| 118 | +### PDF417 |
| 119 | + |
| 120 | +This encodes the input as a real (standard, scannable) [PDF417](https://en.wikipedia.org/wiki/PDF417) barcode (ISO/IEC 15438), a stacked linear barcode made of rows of 17-module code words. It encodes the data with the most compact of the Text, Byte and Numeric compaction modes, chooses the number of columns automatically and adds the Reed-Solomon error correction (over GF(929)) at the level given in the codec name (0 to 8 ; 2 by default). Decoding reads the symbol back and applies Reed-Solomon error correction, so that a damaged code can still be decoded ; it handles the three compaction modes, so that PDF417 barcodes generated by other tools can be read. Like the other barcodes, the output is a grayscale PNG image by default, or plain text with the `-text` variant. |
| 121 | + |
| 122 | +**Codec** | **Conversions** | **Aliases** | **Comment** |
| 123 | +:---: | :---: | --- | --- |
| 124 | +`pdf417` | text <-> PDF417 (image or text) | `pdf-417`, `pdf417-N` (*N* being the error correction level), `pdf417-text`, `pdf417-N-text` | level 2 by default ; the number of columns is chosen automatically |
| 125 | + |
| 126 | +```python |
| 127 | +>>> png = codext.encode(b"codext", "pdf417") |
| 128 | +>>> png[:8] |
| 129 | +b'\x89PNG\r\n\x1a\n' |
| 130 | +>>> codext.decode(png, "pdf417") |
| 131 | +b'codext' |
| 132 | +>>> print(codext.encode("Hi", "pdf417-0-text")) |
| 133 | +████████ █ █ █ ███ █ █ ███ ████ █ █ ████ ████ ██ █ ███ ████ █ █ ████ ███████ █ █ █ █ |
| 134 | +████████ █ █ █ ████ █ █ █ ██████ ██ █ ██ █ ██████ █ ██ █████ █ █ ██ ███████ █ █ █ █ |
| 135 | +████████ █ █ █ ███ █ █ ██████ █ █████ ████ ███ ██ ███ █ ███ █ █ █ ████ ███████ █ █ █ █ |
| 136 | +>>> codext.decode(codext.encode("Hi", "pdf417-0-text"), "pdf417") |
| 137 | +'Hi' |
| 138 | +``` |
| 139 | + |
| 140 | +----- |
| 141 | + |
118 | 142 | ### QR Code |
119 | 143 |
|
120 | 144 | This encodes the input as a real (standard, scannable) [QR code](https://en.wikipedia.org/wiki/QR_code), as opposed to the `fakeqr` codec which only mimics the aspect of one. It uses the byte mode, selects the smallest version (1 to 40) that fits the data for the chosen error correction level (`L`, `M`, `Q` or `H`, given in the codec name, `M` by default) and picks the data mask with the lowest penalty score. Decoding reads the QR code back, recovering its error correction level and mask from the format information and applying Reed-Solomon error correction, so that a damaged QR code can still be decoded ; it also handles the numeric and alphanumeric modes, so that QR codes generated by other tools can be read. Like `fakeqr`, the QR code is a grayscale PNG image by default, or plain text with the `-text` variant. |
|
0 commit comments