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

Modules

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

Macros

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

Constants

  • Size in pixels of the PDF417 end pattern
  • Maximum number of data columns in a PDF417 barcode.
  • Maximum number of rows in a PDF417 barcode.
  • Minimum number of data columns in a PDF417 barcode.
  • Minimum number of rows in a PDF417 barcode.
  • Size in pixels of the PDF417 start pattern

Traits

Functions

  • 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 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.
  • Returns the dimensions of a MicroPDF417 variant as (rows, cols).

Type Aliases