CK-PDFExtractor.Core 0.1.0-preview.7

This is a prerelease version of CK-PDFExtractor.Core.
dotnet add package CK-PDFExtractor.Core --version 0.1.0-preview.7
                    
NuGet\Install-Package CK-PDFExtractor.Core -Version 0.1.0-preview.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CK-PDFExtractor.Core" Version="0.1.0-preview.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CK-PDFExtractor.Core" Version="0.1.0-preview.7" />
                    
Directory.Packages.props
<PackageReference Include="CK-PDFExtractor.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CK-PDFExtractor.Core --version 0.1.0-preview.7
                    
#r "nuget: CK-PDFExtractor.Core, 0.1.0-preview.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CK-PDFExtractor.Core@0.1.0-preview.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CK-PDFExtractor.Core&version=0.1.0-preview.7&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CK-PDFExtractor.Core&version=0.1.0-preview.7&prerelease
                    
Install as a Cake Tool

CK-PDFExtractor.Core

Read text and form fields from PDF files in pure .NET. No Python, nothing else to install.

  • With a template JSON: reads the boxes you define and returns each value with its confidence.
  • Without a template: returns all the text in the document.
  • You choose the mode on every call.

Status: 0.1.0-preview.6 (prerelease, APIs may change). Requires .NET 10 and Windows x64. No internet access is needed at any point — the OCR model ships inside the package and is unpacked to a local cache on first use, so only the first call pays a small extra startup cost.

How it works

PDF -> pictures -> line up with reference picture -> cut out each box -> read text (OCR) -> remove label -> check pattern -> result

Without a template it skips the middle steps and reads the whole page.

Quick start

using CK.PDFExtractor.Core;
using CK.PDFExtractor.Core.Services;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddLogging();
services.AddReceiptExtractionWithSdcb();

using var provider = services.BuildServiceProvider();
using var scope = provider.CreateScope();
var extractor = scope.ServiceProvider.GetRequiredService<ReceiptExtractionService>();

byte[] pdf = await File.ReadAllBytesAsync("document.pdf");

var result = await extractor.ExtractAsync(pdf, "template.json");   // with a template
var all    = await extractor.ExtractAsync(pdf, null);              // whole document

foreach (var f in result.Fields)
    Console.WriteLine($"{f.FieldName} = '{f.RawValue}' ({f.OcrConfidence:F3}) {f.ValidationMessage}");

Sample template.json

{
  "Version": 2,
  "CanonicalTemplatePath": "reference.png",
  "CanonicalDimensions": { "Width": 1200, "Height": 1600 },
  "Fields": [
    {
      "FieldName": "ENGINE_NUMBER",
      "FieldType": "Text",
      "Region": { "X1": 316, "Y1": 656, "X2": 550, "Y2": 719 },
      "Pattern": "^[0-9A-Z]{14}$",
      "Required": true,
      "PageNumber": 1
    }
  ]
}
  • CanonicalTemplatePath is a picture of the blank form, next to the JSON. Region is in that picture's pixels.
  • Each box must hold only the printed label and its value. FieldName must match the printed label (case, _ and spaces are ignored), which is how the label is removed.
  • Pattern is a regex. A mismatch is flagged, not discarded. Required: true does not make the call fail.
  • Several pages in one JSON: set each field's PageNumber and add "PageTemplates": [ { "PageNumber": 2, "CanonicalTemplatePath": "page2.png" } ] for every page after page 1 (page 1 uses the top-level picture).

Template calibration GUI

A calibration GUI for drawing the boxes and generating the template JSON and reference pictures is provided by the author. It is not part of the NuGet package. Ask the author for it.

Sample results

Read Status first. If it is Failed, read Errors. Otherwise check each field. Success only means the pipeline ran, not that every field was found.

1. Several fields, success

Status: Success
ENGINE_NUMBER    161FMJT5072510   0.986   (no message)
HPG_CONTROL_NO   0H1260349854     0.967   (no message)
SBR_NUMBER       22326118         0.989   (no message)

2. Partial success (a field fails its pattern)

Status: Success
HPG_CONTROL_NO   OH1260349938     0.955   Field 'HPG_CONTROL_NO' does not match required pattern '^0H1\d{9}$'.

The value is still returned so you can review or fix it (here the OCR read 0 as the letter O).

3. Fail (nothing found)

Status: Success
ENGINE_NUMBER    ""               0       Field value not found (only label detected).

Status: Failed        <- when the call cannot run (bad template, page cannot be lined up, too few pages)
Errors: ["Template could not be loaded: <reason>"]

4. Whole document, no template

Status: Success        Fields: []
DocumentText:
  Page  X    Y    Width  Height  Confidence  Source  Text
  0     120  84   410    28      0.99        Ocr     SPECIAL BANK RECEIPT
  0     120  130  260    24      0.97        Ocr     SBR No. 22326118

Limits

  • Windows x64 only, English OCR only.
  • OCR can confuse similar characters (0/O, 6/8). Use Pattern to flag them and correct them in your code.
  • Text read straight from a digital PDF has no position (box 0/0/0/0).

License

This package: Apache-2.0. It bundles Ghostscript (AGPL or commercial license), which is fine for company-internal use.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-preview.7 39 9/23/2026
0.1.0-preview.4 38 9/23/2026
0.1.0-preview.3 39 9/23/2026
0.1.0-preview.2 55 9/22/2026
0.1.0-preview.1 63 9/20/2026