Crate pdf417

Source
Expand description

§PDF417 Generator

A no-std and no-alloc PDF417 encoder for embedded applications (also works for std). This library implements mutliple encoding modes for numbers, strings and bytes according to the specification. You can also customize the rendering of the barcodes (size, storage and inverted) and supports both Truncated PDF417 and MicroPDF417.

§Basic Example
const COLS: u8 = 3;
const ROWS: u8 = 5;
const WIDTH: usize = pdf417_width!(COLS);
const HEIGHT: usize = pdf417_height!(ROWS);
 
// High-level encoding
let mut input = [0u16; (ROWS * COLS) as usize];
let (level, _) = PDF417Encoder::new(&mut input, false)
    .append_ascii("Hello, world!").fit_seal().unwrap();
 
// Rendering
let mut storage = [false; WIDTH * HEIGHT];
PDF417::new(&input, ROWS, COLS, level).render(&mut storage[..]);

§Data Segments

You can multiple data segments (aka encoding modes) on a single barcode. The available types are:

  • numeric: efficient encoding of 44+ digit numbers
  • ascii: efficient encoding of text (alphanumeric + punctuation) with support for non-displyable ASCII values which are encoded as raw bytes.
  • bytes: binary data as bytes

An additional UTF-8 mode is available which allows encoding of UTF-8 strings using an ECI identifier and byte encoding mode (note that this encoding takes significantly more space than the ASCII mode).

See the different methods available on PDF417Encoder struct.

§MicroPDF417

This library also supports the generation of MicroPDF417. Here is an example:

const COLS: u8 = 1;
const ROWS: u8 = 11;
const WIDTH: usize = m_pdf417_width!(COLS);
const HEIGHT: usize = m_pdf417_height!(ROWS);

// High-level encoding
let variant = get_variant(ROWS, COLS).unwrap();
let mut input = [0u16; (ROWS * COLS) as usize];
PDF417Encoder::new(&mut input, true)
    .append_num(12345678).seal(variant);

// Rendering
let mut storage = [false; WIDTH * HEIGHT];
MicroPDF417::new(&input, variant).render(&mut storage[..]);

Do not forget to set the micro parameter to true in PDF417Encoder::new.

Re-exports§

pub use high_level::*;

Modules§

ecc
ECC generation for PDF417
high_level
User data to high level encoding conversion functions

Macros§

m_pdf417_height
Calculate the height in pixels of a MicroPDF417 barcode according to the configuration (Rows, Y scale). Only the number of rows is required, other parameters can be omitted in order. Note that the default Y scale is 2.
m_pdf417_width
Calculate the width in pixels of a MicroPDF417 barcode according to the configuration (Columns, X scale). Only the number of columns is required, other parameters can be omitted in order.
pdf417_height
Calculate the height in pixels of a PDF417 barcode according to the configuration (Rows, Y scale). Only the number of rows is required, other parameters can be omitted in order.
pdf417_width
Calculate the width in pixels of a PDF417 barcode according to the configuration (Columns, X scale, Is Truncated). Only the number of columns is required, other parameters can be omitted in order.

Structs§

BoolSliceRenderConfig
Struct used to implement RenderTarget for [bool]
ByteSliceRenderConfig
Struct used to implement RenderTarget for [u8].
MicroPDF417
Configuration and Rendering of MicroPDF417 barcodes.
PDF417
Configuration and Rendering of PDF417 barcodes.

Constants§

END_PATTERN_LEN
Size in pixels of the PDF417 end pattern
MAX_COLS
Maximum number of data columns in a PDF417 barcode.
MAX_ROWS
Maximum number of rows in a PDF417 barcode.
MIN_COLS
Minimum number of data columns in a PDF417 barcode.
MIN_ROWS
Minimum number of rows in a PDF417 barcode.
START_PATTERN_LEN
Size in pixels of the PDF417 start pattern

Traits§

RenderTarget
A receiver for rendering PDF417 barcodes.

Functions§

find_variant
Find a suitable variant that has at least capacity free codeword slots. None if capacity is too large to be stored by a MicroPDF417.
get_variant
Get the variant number for a dimension (rows, cols). Returns None the combinaison of rows and cols is invalid (not supported) according to the MicroPDF417 specification.
variant_dim
Returns the dimensions of a MicroPDF417 variant as (rows, cols).

Type Aliases§

PDF417Config
(rows, cols, (scaleX, scaleY), inverted)