InPoint.Cloud.OpenBarcode
0.1.0
See the version list below for details.
dotnet add package InPoint.Cloud.OpenBarcode --version 0.1.0
NuGet\Install-Package InPoint.Cloud.OpenBarcode -Version 0.1.0
<PackageReference Include="InPoint.Cloud.OpenBarcode" Version="0.1.0" />
<PackageVersion Include="InPoint.Cloud.OpenBarcode" Version="0.1.0" />
<PackageReference Include="InPoint.Cloud.OpenBarcode" />
paket add InPoint.Cloud.OpenBarcode --version 0.1.0
#r "nuget: InPoint.Cloud.OpenBarcode, 0.1.0"
#:package InPoint.Cloud.OpenBarcode@0.1.0
#addin nuget:?package=InPoint.Cloud.OpenBarcode&version=0.1.0
#tool nuget:?package=InPoint.Cloud.OpenBarcode&version=0.1.0
OpenBarcode
An open-source barcode reader for .NET that reads images and PDF files with managed code only: no native libraries, no System.Drawing, no Ghostscript or PDFium. It runs anywhere .NET runs (Windows, Linux, macOS, containers, Azure Functions) and targets .NET Standard 2.0 and .NET 8.
using InPoint.Cloud.OpenBarcode;
var reader = new BarcodeReader();
foreach (var barcode in reader.ReadFile("invoice.pdf"))
Console.WriteLine($"page {barcode.PageNumber}: {barcode.Format} {barcode.Text}");
Install
dotnet add package InPoint.Cloud.OpenBarcode
dotnet tool install -g InPoint.Cloud.OpenBarcode.Cli # command: openbarcode
The namespace is InPoint.Cloud.OpenBarcode.
What it reads
Symbologies: QR Code, Data Matrix, PDF417, Aztec, Code 128 (incl. GS1-128), Code 39, Code 93, Codabar, EAN-13, EAN-8, UPC-A, UPC-E, ITF, GS1 DataBar (+ Expanded), MaxiCode (clean crops only) and MSI (opt-in).
Images: PNG, JPEG, BMP, GIF, TIFF (all pages, incl. CCITT G3/G4 fax compression), TGA, PSD, PBM/PGM/PPM. Transparent images are composited on white, so black-on-transparent barcode PNGs work.
PDFs: two kinds of content are searched on every page:
- Embedded images such as scans: JPEG (DCT), Flate, LZW, CCITT G3/G4 and JBIG2 (generic and symbol-coded),
in gray, RGB, CMYK and indexed colour, image masks and
/Decodeinversions. - Vector graphics: barcodes that PDF generators draw as filled rectangles, paths or stroked lines (reportlab, iText, Crystal Reports, label printers' "print to PDF", ...). The reader rasterizes the page's paths at 300 dpi with its own scanline renderer and decodes the result.
The same code found twice on one page (for example as both an image and vector art) is reported once.
Usage
var reader = new BarcodeReader(new BarcodeReaderOptions
{
Formats = BarcodeFormat.QrCode | BarcodeFormat.Code128, // fewer formats = faster, fewer false positives
PdfFirstPage = 1,
PdfLastPage = 3,
});
// From a path, a Stream or a byte[]; the type is detected from the content, not the extension.
IReadOnlyList<BarcodeResult> results = reader.ReadFile("scan.tif");
// PDFs: find out which images had to be skipped.
var warnings = new List<string>();
results = reader.Read(File.ReadAllBytes("doc.pdf"), warnings);
// Pixels you already have (System.Drawing, SkiaSharp, ImageSharp, a camera frame, ...).
var image = GrayImage.FromPixels(bgraBytes, width, height, PixelLayout.Bgra32, stride);
results = reader.Read(image);
Each BarcodeResult has Text, Format, RawBytes, Points (corner or end points, in pixels of the image it
was decoded from), Source (Image, PdfImage, PdfVector), PageNumber (PDFs, 1-based) and FrameIndex
(TIFF page, or image index on a PDF page).
BarcodeReader is immutable and thread-safe; share one instance.
Options
| Option | Default | |
|---|---|---|
Formats |
BarcodeFormat.Default |
Everything except MSI. |
TryHarder |
true |
Denser scanning. |
TryInverted |
true |
Also try light-on-dark. |
AutoRotate |
true |
Also look for 1D codes turned 90°. 2D codes are found at any angle regardless. |
ReadMultiple |
true |
Find every code, not just the first. |
PdfReadImages / PdfReadVectorGraphics |
true |
Turn either PDF source off. |
PdfRenderDpi |
300 |
Resolution for vector graphics. |
PdfMaxRenderPixels |
40 M | Caps memory for huge pages; DPI is lowered to fit. |
PdfFirstPage / PdfLastPage |
all | Page range. |
PdfPassword |
For encrypted PDFs. | |
CharacterSet |
Fallback encoding for byte-mode data, e.g. "ISO-8859-1". |
Command line
dotnet run --project src/OpenBarcode.Cli -- invoice.pdf scans/*.tif
dotnet run --project src/OpenBarcode.Cli -- --json --formats qr,datamatrix label.png
Run with --help for all options. Output is file[:page]<TAB>format<TAB>text; the exit code is 0 when
something was found, 1 when nothing was, 2 on errors.
Performance
A full A4 page scanned at 300 dpi takes roughly 0.5–2 s with the thorough defaults on one core.
Restricting Formats, setting ReadMultiple = false (stop at the first code) or TryHarder = false
makes it several times faster. Pages are independent, so batches parallelise well.
Limitations
- Barcodes set as text in a barcode font inside a PDF are not detected (glyphs are not rendered). Most generators draw bars as paths or images, which work.
- JPEG 2000 (
JPXDecode) images in PDFs are skipped with a warning; no managed decoder is used. - The vector renderer ignores clipping paths, soft masks and shading patterns.
- Damaged, very blurry or strongly perspective-distorted photos may not decode; this is a document reader first, not a camera scanner.
How it works
file ──► sniff type ─┬─► image decoders (StbImageSharp, LibTiff.NET, built-in PNM) ──────────────┐
└─► PdfPig ─┬─► embedded images ─► filters (+ managed JBIG2) ─► grayscale ─┤
└─► paths ─► scanline rasterizer (this project) ───────────────┤
▼
ZXing.Net detectors ◄── quiet-zone padding, upscaling of tiny images,
90° pass for 1D, blob crops for Data Matrix/Aztec,
fragment and duplicate filtering
ZXing's Data Matrix and Aztec detectors search outward from the image centre, so on a page with several codes they only see one. The reader proposes compact ink blobs and gives each its own crop. Partial reads that ZXing can report inside a longer 1D barcode (a "UPC-E" made of half an EAN-13) are filtered out.
Building and testing
Needs the .NET 10 SDK (for the .slnx solution file); the library itself targets .NET Standard 2.0 and .NET 8.
dotnet build
dotnet test
The tests generate barcodes in every supported symbology and file format, build PDFs with hand-written content
streams and image dictionaries, and read real-world-style samples made by reportlab, poppler, ImageMagick and
jbig2enc (tests/samples).
License
Apache-2.0. See THIRD-PARTY-NOTICES.md for the libraries it builds on.
Releasing
Push a tag such as v0.1.0 (or v0.2.0-beta.1 for a prerelease). The Release workflow builds, tests, packs and
publishes both packages to nuget.org under the InPoint.Cloud account using Trusted Publishing, then creates a
GitHub release with the packages attached. The package version comes from the tag.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- BitMiracle.LibTiff.NET (>= 2.4.660)
- PdfPig (>= 0.1.16)
- PdfPig.Filters.Jbig2.PdfboxJbig2 (>= 0.1.16)
- StbImageSharp (>= 2.30.16)
- ZXing.Net (>= 0.16.11)
-
net8.0
- BitMiracle.LibTiff.NET (>= 2.4.660)
- PdfPig (>= 0.1.16)
- PdfPig.Filters.Jbig2.PdfboxJbig2 (>= 0.1.16)
- StbImageSharp (>= 2.30.16)
- ZXing.Net (>= 0.16.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.