Skip to content

Commit f4ff5c0

Browse files
committed
Added codec: pdf417
1 parent 055ca27 commit f4ff5c0

4 files changed

Lines changed: 892 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ CACTCGGTCGGCCATATGTTCGGCCATATGTTCGTCTGTTCACTCGCCCATACACT
264264
- [X] `aztec`: real (scannable) Aztec code (ISO/IEC 24778) ; optimal high-level compaction, error correction percentage given in the name (e.g. `aztec-33` ; 23% by default), rendered as an image or, with `aztec-text`, as plain text ; decoding applies Reed-Solomon error correction
265265
- [X] `datamatrix`: real (scannable) Data Matrix barcode (ISO/IEC 16022, ECC200) ; most compact of the ASCII, C40, Text, X12 and EDIFACT schemes, square or rectangular (`datamatrix-rect`), rendered as an image or, with `datamatrix-text`, as plain text ; decoding applies Reed-Solomon error correction
266266
- [X] `fakeqr`: hides the input bits as the modules of something that looks like a QR code but is not one, either an image or, with the `fakeqr-text` variant, plain text (the 8 QR masks are available as `fakeqr-0` to `fakeqr-7`)
267+
- [X] `pdf417`: real (scannable) PDF417 stacked barcode (ISO/IEC 15438) ; most compact of the Text, Byte and Numeric modes, error correction level given in the name (e.g. `pdf417-5` ; 2 by default), rendered as an image or, with `pdf417-text`, as plain text ; decoding applies Reed-Solomon error correction
267268
- [X] `qr`: real (scannable) QR code ; byte mode, error correction level given in the name (`qr-l`, `qr-m`, `qr-q`, `qr-h` ; M by default), rendered as an image or, with `qr-text`, as plain text ; decoding applies Reed-Solomon error correction
268269

269270
#### [BaseXX](https://python-codext.readthedocs.io/en/latest/enc/base.html)

‎docs/pages/enc/barcodes.md‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.
22

33
-----
44

@@ -115,6 +115,30 @@ b'this is a test'
115115

116116
-----
117117

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+
118142
### QR Code
119143

120144
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.

‎src/codext/barcodes/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
from .aztec import *
33
from .datamatrix import *
44
from .fakeqr import *
5+
from .pdf417 import *
56
from .qr import *

0 commit comments

Comments
 (0)