Skip to main content

Overview

Barcode detection identifies and decodes barcodes found in document pages. Each detected barcode is returned as a structured page fragment with its decoded value, barcode type, and bounding box — allowing downstream processing to handle barcodes separately from text, tables, and other content. Barcode detection is available in the model03 OCR model and is enabled via a flag in ParsingOptions.

Enabling Barcode Detection

Set barcode_detection="true" in your ParsingOptions along with ocr_model="model03":
Barcode detection requires Tensorlake Python SDK version 0.2.91 or later. Run pip install --upgrade tensorlake before using this feature.
from tensorlake import DocumentAI, ParsingOptions

doc_ai = DocumentAI(api_key="YOUR_TENSORLAKE_CLOUD_API_KEY")

file_id = doc_ai.upload(path="barcode_file.pdf")

parsing_options = ParsingOptions(
    ocr_model="model03",
    barcode_detection="true",
)

parse_id = doc_ai.read(
    file_id=file_id,
    parsing_options=parsing_options,
)

result = doc_ai.wait_for_completion(parse_id)

How It Works

When barcode detection is enabled, the pipeline:
  1. Parses each page into fragments (text, tables, barcodes, etc.)
  2. Runs a barcode detector and decoder over the page image
  3. Emits fragment_type: "barcode" entries alongside other page fragments
  4. Includes bounding boxes and page dimensions so barcodes can be positioned or highlighted in a viewer

Fragment Output

Each detected barcode is returned as a fragment with the following structure:
{
    "fragment_type": "barcode",
    "content": {
        "content": "PDF417: 4QGDkVjpF7nuGhQiOgLHwc",
        "html": null
    },
    "reading_order": 9,
    "bbox": {
        "x1": 2,
        "y1": 444,
        "x2": 207,
        "y2": 475
    }
}
FieldDescription
fragment_typeAlways "barcode" for barcode fragments
content.contentThe barcode type and decoded value, formatted as "<TYPE>: <value>"
reading_orderPosition of this fragment in reading order relative to other page fragments
bboxBounding box coordinates (x1, y1, x2, y2) in page pixels

Common Use Cases

Barcodes appear across many operational document types:
  • Shipping labels and packing slips — tracking numbers and carrier codes
  • Lab reports and sample labels — specimen and sample IDs
  • Insurance documents — claim IDs and policy references
  • Utility bills, tickets, and receipts — account numbers and confirmation codes
With barcodes returned as structured fragments alongside text and tables, you can:
  • Match barcode values to internal IDs (shipment, claim, order, patient)
  • Validate that a barcode value matches a printed text label on the same page
  • Flag documents where an expected barcode is missing or unreadable
  • Render barcode overlays in a document viewer using the provided bounding boxes