Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bce — Barcode Extractor

bce is a command-line tool that reads every barcode from a PDF and writes the results to a JSON file.

How it works

For each page of the input PDF, bce:

  1. Renders the page as a raster image at 300 DPI.
  2. Composites any transparent pixels onto a white background.
  3. Converts the image to grayscale luminance.
  4. Runs ZXing barcode detection across all supported formats (TryHarder, TryRotate, TryDownscale all enabled).
  5. Blanks out every detected barcode region (replaces it with light blue) and repeats detection — up to five times per page — so that barcodes hidden behind or near other barcodes are also found.
  6. Collects all unique barcodes (deduplicated by content) and records their type and text.

The output is a JSON array — one entry per page — listing the page number and any barcodes found on that page.

Usage

bce <input-path> <output-path> [--intermediate <path>] [--escape-unicode]
Argument Description
input-path Path to the PDF file to process.
output-path Path where the extracted barcode JSON will be written.
--intermediate, -i Optional directory for debug PNG output. Saves one image per page per detection pass so you can see which barcodes were found in which iteration.
--escape-unicode Escape non-ASCII characters as \uXXXX in the JSON output. By default, Unicode characters are written as-is.

Output format

[
  {
    "Page": 1,
    "Barcodes": [
      { "Type": "QRCode", "Contents": "https://example.com" },
      { "Type": "Code128", "Contents": "ABC-12345" }
    ]
  },
  {
    "Page": 2,
    "Barcodes": []
  }
]

Building

Requires .NET 9. On macOS with Homebrew:

brew install dotnet@9
dotnet build

The included code.sh script sets up the correct DOTNET_ROOT when dotnet@9 is installed via Homebrew and opens the project in VS Code.

Licenses and acknowledgements

See THIRD-PARTY-NOTICES.md for dependency license and redistribution notices.

This project is built on three open-source libraries:

  • ZXingCpp — Apache License 2.0
    .NET binding for zxing-cpp, a C++ port of the ZXing ("Zebra Crossing") barcode scanning library. Used to detect and decode barcodes from grayscale image data.

  • Docnet.Core — MIT License
    .NET wrapper around PDFium, Google's PDF rendering engine. Used to open PDF files, iterate pages, and render each page to a pixel buffer.

  • SkiaSharp — MIT License
    .NET binding for Skia, Google's 2D graphics library. Used to encode intermediate debug images as PNG files.

About

CLI tool to extract barcodes from PDFs

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages