barcode

Generate and add a barcode to pages

Usage

pdftl <input> barcode <specs>... [layer_name <name>] output <file>

Details

The barcode operation generates a barcode (e.g., QR code, DataMatrix, Code128) from specified text or templates and overlays it onto the input document.

Syntax

[page_range]!<data>![(options)]

  • page_range: Standard page selection (e.g., 1-5, even, 1-end). Defaults to all pages if omitted.

  • data: The string to encode into the barcode. Supports dynamic template variables like {n} (page number within the sequence) and {page} (absolute page number).

  • options: A comma-separated list of key=value pairs enclosed in parentheses.

Positioning & Layout

The barcode operation uses a strictly Cartesian coordinate system, matching the add_text operation.

  • position: Use preset anchors (top-left, top-right, bottom-center, mid-center, etc.). These place the barcode exactly flush against the visible page boundaries.

  • offset-x / offset-y: Cartesian shifts applied after the base position. Use these to add inward margins. For example, if positioned top-right, use offset-x=-36pt to push the barcode left, and offset-y=-36pt to push it down.

  • x / y: Absolute coordinates measured from the bottom-left corner of the page. Mutually exclusive with position.

  • width: The physical dimension of the rendered barcode (e.g., 72pt, 1.5in). The height is calculated automatically to preserve the exact aspect ratio of the generated matrix.

Barcode Options

  • format: The type of barcode to generate (default: QRCode).

  • scale: Internal rendering resolution multiplier to ensure the generated matrix is crisp before scaling it to the physical width (default: 10).

Examples

Basic barcode

pdftl in.pdf barcode '!https://github.com/pdftl/pdftl!' output out.pdf

Tags: in_place, overlay, layer, barcode

Source: pdftl.operations.barcode

Read online: https://pdftl.readthedocs.io/en/latest/operations/barcode.html

Type: Operation