ZXing Barcode icon

ZXing Barcode

Generate and scan barcodes using ZXing library

Actions2

Overview

This node enables barcode generation and scanning using the ZXing library. It supports a wide variety of barcode formats including QR Code, Code 128, EAN, UPC, Data Matrix, PDF 417, Aztec, and others.

  • Generate Operation: Converts input text into a barcode image with customizable format, size, margin, and error correction level (for QR codes). Useful for creating barcodes for product labels, tickets, or encoding URLs and data.
  • Scan Operation: Decodes barcodes from images provided as binary data or base64 strings. Supports multiple image processing attempts to improve decoding success. Ideal for extracting information from scanned barcodes in workflows.

Practical examples:

  • Automatically generate QR codes for URLs or contact info to embed in emails or documents.
  • Scan product barcodes from uploaded images to retrieve product IDs or inventory data.

Properties

Name Meaning
Operation Choose between "Generate" (create barcode) or "Scan" (decode barcode from image).

When Operation = Generate

Name Meaning
Barcode Format The type of barcode to generate. Options: QR Code, Code 128, Code 39, Code 93, EAN-8, EAN-13, UPC-A, UPC-E, Data Matrix, PDF 417, Aztec, Codabar, ITF.
Text to Encode The text or data string to encode into the barcode.
Width Width of the generated barcode image in pixels.
Height Height of the generated barcode image in pixels.
Error Correction Level For QR Codes only: level of error correction to apply. Options: Low (7%), Medium (15%), Quartile (25%), High (30%).
Margin Margin (quiet zone) around the barcode in pixels.

When Operation = Scan

Name Meaning
Image Source Source of the image to scan: "Binary Data" (from previous node's binary output) or "Base64" string.
Binary Property (If Image Source is Binary) Name of the binary property containing the image data.
Base64 Data (If Image Source is Base64) Base64 encoded image string to decode.
Try Harder Whether to enable more intensive decoding attempts (slower but more accurate).
Return Format Info Whether to include detected barcode format details in the output.

Output

  • Generate Operation outputs an object per input item with:

    • json containing:
      • format: barcode format used
      • text: original text encoded
      • width, height: dimensions of the generated image
      • size: size in bytes of the PNG image buffer
    • binary.data: PNG image data of the generated barcode encoded as base64, with appropriate MIME type and file extension.
  • Scan Operation outputs an object per input item with:

    • json containing:
      • text: decoded text from the barcode
      • Optionally, if enabled:
        • format: human-readable barcode format name
        • formatType: internal barcode format identifier
      • timestamp: timestamp of decoding
      • numBits: number of bits decoded
      • imageInfo: width, height, and channels of the processed image
    • pairedItem: index linking output to input item

Dependencies

  • Uses the ZXing library (@zxing/library) for barcode encoding and decoding.
  • Uses sharp for image processing tasks such as resizing, greyscale conversion, normalization, sharpening, and raw pixel manipulation.
  • No external API keys or credentials are required.
  • Requires n8n environment capable of handling binary data and image buffers.

Troubleshooting

  • Common Issues:

    • Missing or empty "Text to Encode" when generating barcodes will cause an error.
    • Providing invalid or missing binary/base64 image data for scanning will cause errors.
    • Poor image quality, colored backgrounds, damaged barcodes, or low resolution may prevent successful scanning.
  • Error Messages:

    • "Text to encode is required for generation": Ensure the input text property is not empty.
    • "No binary data found for property ...": Verify that the previous node outputs binary data under the specified property name.
    • "Base64 data is required for scanning": Provide valid base64 image data when selected as source.
    • "No barcode found in the provided image...": Try enabling "Try Harder", use higher quality images, or better lighting conditions.
    • "Failed to decode barcode after trying multiple image processing approaches": Indicates decoding failed despite multiple attempts; check image validity and barcode visibility.
    • "Failed to process image...": Input might not be a valid image file; verify input data.

Links and References

Discussion