Table of Contents

Class BarcodeSplitting

Namespace
LMKit.Extraction.Barcodes
Assembly
LM-Kit.NET.dll

Splits a batch (a scanned PDF, a multi-page TIFF, any multi-page document) into separate documents by barcodes: separator sheets, first or last page markers, a value that changes from one document to the next, or a value shared by all the pages of a document.

public sealed class BarcodeSplitting
Inheritance
BarcodeSplitting
Inherited Members

Examples

Example: separator sheets in a scanned batch

using LMKit.Extraction.Barcodes;

var splitter = new BarcodeSplitting(new BarcodeSplittingOptions { Mode = BarcodeSplitMode.SeparatorPage, RemoveBlankPageAfterSeparator = true // duplex scan: drop the back of each sheet });

BarcodeSplittingResult result = splitter.SplitToFiles("batch.pdf", "output"); foreach (BarcodeSegment document in result.Segments) { Console.WriteLine($"{document.Label}: pages {document.StartPage}-{document.EndPage} => {document.OutputPath}"); }

Example: every page carries its case number; gather each case

using LMKit.Extraction.Barcodes;

var splitter = new BarcodeSplitting(new BarcodeSplittingOptions { Mode = BarcodeSplitMode.GroupByValue, Match = new BarcodeMatchRule { Pattern = @"^CASE-\d+$" }, FileNameTemplate = "{value}" });

BarcodeSplittingResult result = await splitter.SplitToFilesAsync("mailroom.pdf", "cases");

Remarks

Deterministic: barcodes are read by the ZXing-C++ reader compiled into the LM-Kit.ocr native library. No model is loaded and no AI feature is involved, unlike the content-based DocumentSplitting.

What a barcode means is Mode; which barcodes count is Match; the document's value (its label, its file name, its grouping key) is ValuePattern.

Every operation exists for four inputs (an Attachment, a file path, bytes, a stream), synchronously and asynchronously, and in four outputs:

  • Split: find the documents, write nothing (preview, routing, auditing).
  • SplitToAttachments: produce each document in memory.
  • SplitToFiles: write each document to a directory, named by FileNameTemplate.
  • SplitToStreams: write each document to a stream you open (blob storage, a response...).

A page that cannot be read is never a separator: it stays content and is reported in FailedPages. An instance holds options and event handlers only; it can run several splits, one after the other or at once.

Constructors

BarcodeSplitting()

Initializes a splitter with the default options: any valid barcode marks a separator sheet, which is removed.

BarcodeSplitting(BarcodeSplittingOptions)

Initializes a splitter with the specified options.

Properties

Options

Gets the options splits run with. Changing them affects the next run.

Methods

Split(Attachment, CancellationToken)

Finds the documents of a batch without writing anything: their pages, values and barcodes, and the role of every scanned page.

Split(byte[], string, string, CancellationToken)

Finds the documents of a batch held in memory without writing anything.

Split(Stream, string, string, CancellationToken)

Finds the documents of a batch read from a stream (left open) without writing anything.

Split(string, string, CancellationToken)

Finds the documents of a batch file without writing anything.

SplitAsync(Attachment, CancellationToken)

Finds the documents of a batch without writing anything: their pages, values and barcodes, and the role of every scanned page.

SplitAsync(byte[], string, string, CancellationToken)

Finds the documents of a batch held in memory without writing anything.

SplitAsync(Stream, string, string, CancellationToken)

Finds the documents of a batch read from a stream (left open) without writing anything.

SplitAsync(string, string, CancellationToken)

Finds the documents of a batch file without writing anything.

SplitToAttachments(Attachment, CancellationToken)

Splits a batch into documents held in memory, in Documents and each Document, named by FileNameTemplate.

SplitToAttachments(byte[], string, string, CancellationToken)

Splits a batch held in memory into documents held in memory.

SplitToAttachments(Stream, string, string, CancellationToken)

Splits a batch read from a stream (left open) into documents held in memory.

SplitToAttachments(string, string, CancellationToken)

Splits a batch file into documents held in memory.

SplitToAttachmentsAsync(Attachment, CancellationToken)

Splits a batch into documents held in memory, in Documents and each Document, named by FileNameTemplate.

SplitToAttachmentsAsync(byte[], string, string, CancellationToken)

Splits a batch held in memory into documents held in memory.

SplitToAttachmentsAsync(Stream, string, string, CancellationToken)

Splits a batch read from a stream (left open) into documents held in memory.

SplitToAttachmentsAsync(string, string, CancellationToken)

Splits a batch file into documents held in memory.

SplitToFiles(Attachment, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch into files in outputDirectory (created when missing), named by FileNameTemplate, existing files handled by FileConflict. Two documents of one run never share a file.

SplitToFiles(byte[], string, string, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch held in memory into files in outputDirectory.

SplitToFiles(Stream, string, string, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch read from a stream (left open) into files in outputDirectory.

SplitToFiles(string, string, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch file into files in outputDirectory.

SplitToFilesAsync(Attachment, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch into files in outputDirectory (created when missing), named by FileNameTemplate, existing files handled by FileConflict. Two documents of one run never share a file.

SplitToFilesAsync(byte[], string, string, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch held in memory into files in outputDirectory.

SplitToFilesAsync(Stream, string, string, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch read from a stream (left open) into files in outputDirectory.

SplitToFilesAsync(string, string, string, IProgress<PdfSplitterProgressEventArgs>, CancellationToken)

Splits a batch file into files in outputDirectory.

SplitToStreams(Attachment, Func<BarcodeSegment, Stream>, bool, CancellationToken)

Splits a batch into streams you open: openPart is asked for a writable stream for each document (its OutputName is already set), the document is written to it and the stream is flushed, then disposed unless leaveOpen.

SplitToStreams(byte[], string, Func<BarcodeSegment, Stream>, string, bool, CancellationToken)

Splits a batch held in memory into streams you open.

SplitToStreams(Stream, string, Func<BarcodeSegment, Stream>, string, bool, CancellationToken)

Splits a batch read from a stream (left open) into streams you open.

SplitToStreams(string, Func<BarcodeSegment, Stream>, string, bool, CancellationToken)

Splits a batch file into streams you open.

SplitToStreamsAsync(Attachment, Func<BarcodeSegment, Stream>, bool, CancellationToken)

Splits a batch into streams you open: openPart is asked for a writable stream for each document (its OutputName is already set), the document is written to it and the stream is flushed, then disposed unless leaveOpen.

SplitToStreamsAsync(byte[], string, Func<BarcodeSegment, Stream>, string, bool, CancellationToken)

Splits a batch held in memory into streams you open.

SplitToStreamsAsync(Stream, string, Func<BarcodeSegment, Stream>, string, bool, CancellationToken)

Splits a batch read from a stream (left open) into streams you open.

SplitToStreamsAsync(string, Func<BarcodeSegment, Stream>, string, bool, CancellationToken)

Splits a batch file into streams you open.

Events

PageScanned

Raised after each page is scanned, in page order; set Cancel to stop scanning.

PartWritten

Raised after each document is produced; set Cancel to write no more.

Share