naps2/NAPS2.Sdk
Ben Olden-Cooligan 79bba70370 Improve OCR text alignment
This is nearly a full rewrite of the alignment code. Position is now based on the line baseline (provided by Tesseract) and the font size is smarter (defaulting to Tesseract's provided value with various adjustments).

The goals were:
- Have Ctrl+F highlight the word as accurately as possible.
- Have Ctrl+A/Ctrl+C end up with text that matches the original as closely as possible.
- Have PdfSharp and Pdfium produce consistent output.
On my test cases all goals are fully met.

#236
2024-03-26 19:05:17 -07:00
..
_doc Sdk: Doc cross-links 2023-12-30 10:02:37 -08:00
Images Undo/redo 2024-03-04 20:50:35 -08:00
ImportExport Run MAPISendMail on the UI thread 2024-01-14 19:27:53 -08:00
Lang/Resources Update language files 2024-03-10 19:37:31 -07:00
Ocr Improve OCR text alignment 2024-03-26 19:05:17 -07:00
Pdf Improve OCR text alignment 2024-03-26 19:05:17 -07:00
Platform Sane: Rework non-deterministic ID handling 2024-02-04 17:56:32 -08:00
Remoting Simplify twain type names 2024-03-17 17:51:01 -07:00
Scan Add debug logging for scan start 2024-03-18 09:28:28 -07:00
Serialization Keep proto compatibility 2024-01-03 16:12:58 -08:00
Testing Fix a bunch of warnings 2022-07-02 15:13:31 -07:00
Threading Use EtoInvoker instead of SyncContextInvoker 2023-12-07 21:10:03 -08:00
Unmanaged Make NAPS2.Util classes internal or move to NAPS2.Lib 2023-04-30 14:17:55 -07:00
Util Add a CopyDirectory helper 2024-01-30 21:08:50 -08:00
.gitignore Move ClientCreds to NAPS2.Lib.Common and avoid custom prebuild 2022-07-29 22:09:34 -07:00
LICENSE Update copyright year to 2024 2023-12-30 14:45:47 -08:00
NAPS2.Sdk.csproj Upgrade packages 2024-03-19 17:01:32 -07:00
README.md Sdk: Add WPF package to readme 2023-12-30 12:37:42 -08:00

NAPS2.Sdk

NuGet

NAPS2.Sdk is a fully-featured scanning library, supporting WIA, TWAIN, SANE, and ESCL scanners on Windows, Mac, and Linux.

Packages

NAPS2.Sdk is modular, and depending on your needs you may have to reference a different set of packages.

Required Packages

Optional Packages

Usage

// Set up
using var scanningContext = new ScanningContext(new GdiImageContext());
var controller = new ScanController(scanningContext);

// Query for available scanning devices
var devices = await controller.GetDeviceList();

// Set scanning options
var options = new ScanOptions
{
    Device = devices.First(),
    PaperSource = PaperSource.Feeder,
    PageSize = PageSize.A4,
    Dpi = 300
};

// Scan and save images
int i = 1;
await foreach (var image in controller.Scan(options))
{
    image.Save($"page{i++}.jpg");
}

// Scan and save PDF
var images = await controller.Scan(options).ToListAsync();
var pdfExporter = new PdfExporter(scanningContext);
await pdfExporter.Export("doc.pdf", images);

More samples:

Also see:

Drivers

Windows Mac Linux
WIA X
TWAIN X *
Apple X
SANE X X
ESCL X X X

WIA (Windows Image Acquisition) is a Microsoft technology for scanners (and cameras). Many scanners provide WIA drivers for Windows.

TWAIN is a cross-platform standard for image acquisition. Many scanners provide TWAIN drivers for Windows and/or Mac.

Apple's ImageCaptureCore provides access to TWAIN and ESCL scanners on Mac devices.

SANE is an open-source API and set of backends for various scanners. Primarily for Linux, supported devices use backends made by open-source contributors or the manufacturer themselves.

ESCL, also known as Apple AirScan, is a standard protocol for scanning over a network. Many modern scanners support ESCL, and as it's a network protocol, specific drivers aren't required. ESCL can also be used over a USB connection in some cases.

Choosing a Driver

Each platform has a default driver (WIA on Windows, Apple on Mac, and SANE on Linux). To use another driver, you only need to specify it when querying for devices:

var devices = await controller.GetDeviceList(Driver.Twain);

Worker Processes

Using the TWAIN driver on Windows usually requires the calling process to be 32-bit. If you want to use TWAIN from a 64-bit process, NAPS2 provides a 32-bit worker process:

// Reference the NAPS2.Sdk.Worker.Win32 package and call this method
scanningContext.SetUpWin32Worker();

Contributing

Looking to contribute to NAPS2 or NAPS2.Sdk? Have a look at the wiki.