Scanner automation scripts in C# (.NET 8) and Python - CLI wrappers for NAPS2 with auto-detection, named parameters, and multi-format output.
These scripts provide a streamlined command-line interface for document scanning using NAPS2 as the backend. Both scripts offer identical functionality: automatic scanner detection, support for WIA and TWAIN drivers, and can save scans in multiple formats (PNG, JPEG, TIFF, BMP, PDF) with customizable resolution and color settings.
- âś… Two implementations - C# (.NET 8) and Python 3.7+
- âś… Identical functionality - Same parameters and behavior
- âś… Automatic scanner detection - No need to remember device names
- âś… Multiple output formats - PNG, JPEG, TIFF, BMP, PDF
- âś… Flexible DPI settings - From 75 to 1200+ DPI
- âś… Color mode options - Color, grayscale, black & white
- âś… ADF and flatbed support - Works with document feeders and glass beds
- âś… Batch scanning - Multiple pages automatically numbered
- âś… Cross-platform - Both scripts work on Windows, macOS, and Linux
scanner.cs- C# (.NET 8) implementationscanner.py- Python implementation (identical functionality)README.md- This documentation
Download and install NAPS2 from:
- Official website: https://www.naps2.com/download
- Recommended version: 8.1.4 or newer
Installation Steps:
- Download
naps2-8.1.4-win-x64.exe(or appropriate version for your OS) - Run the installer with default settings
- Important: Make sure NAPS2 is added to your system PATH
Verify NAPS2 installation:
NAPS2.Console --version
# Should show version informationEnsure your scanner has proper drivers installed:
- WIA drivers (Windows Image Acquisition) - Usually installed automatically
- TWAIN drivers (optional) - Often more reliable for business scanners
Download and install from: https://dotnet.microsoft.com/download/dotnet/8.0
Verify installation:
dotnet --version
# Should show 8.0.x or higherDownload from: https://www.python.org/downloads/
Verify installation:
python --version
# Should show 3.7.x or higherNo additional packages required - uses only Python standard library.
Both scripts have identical command-line interfaces:
# C# version
dotnet run scanner.cs [options]
# Python version
python scanner.py [options]| Option | Short | Description | Default |
|---|---|---|---|
--output <folder> |
-o |
Output folder path | scanned_pages |
--prefix <name> |
-p |
File name prefix | page |
--format <ext> |
-f |
Output format (png, jpg, tiff, bmp, pdf) | png |
--dpi <number> |
-d |
Scanning resolution | 300 |
--color <mode> |
-c |
Color mode (color, gray, bw) | color |
--source <src> |
-s |
Paper source (feeder, glass) | feeder |
--device <name> |
Specific scanner device name | auto-detect | |
--driver <type> |
Scanner driver (wia, twain) | wia |
|
--help |
-h |
Show help information |
All examples work identically with both scripts (just change the command):
Simple scan with defaults:
# C# version
dotnet run scanner.cs
# Python version
python scanner.py
# Output: scanned_pages/page_0001.png (300 DPI, color, ADF)Show help:
python scanner.py --help
dotnet run scanner.cs --helpScan to specific folder:
python scanner.py --output "D:\Documents\Scans"
# Output: D:\Documents\Scans\page_0001.pngCustom file prefix and format:
python scanner.py --prefix "invoice" --format jpg --output "C:\Invoices"
# Output: C:\Invoices\invoice_0001.jpg, invoice_0002.jpg, etc.High-resolution scanning:
python scanner.py --dpi 600 --format tiff --prefix "document_hq"
# Output: scanned_pages/document_hq_0001.tiff (600 DPI color TIFF)Web-optimized scanning:
python scanner.py --dpi 150 --format jpg --color gray --prefix "web"
# Output: scanned_pages/web_0001.jpg (150 DPI grayscale JPEG)PDF multi-page document:
python scanner.py --format pdf --prefix "contract" --color bw
# Output: scanned_pages/contract.pdf (all pages in one PDF)Specific scanner device:
python scanner.py --device "Xerox WIA - ETE84DEC0F2B58" --source feederUse TWAIN driver:
python scanner.py --driver twain --format pdf --prefix "report"Flatbed scanning:
python scanner.py --source glass --dpi 600 --format png --prefix "photo"Daily document scanning:
# Windows
python scanner.py --prefix "daily_%DATE%" --format pdf
# Linux/macOS
python scanner.py --prefix "daily_$(date +%Y%m%d)" --format pdfInvoice processing:
python scanner.py --output "C:\Accounting\Invoices" --prefix "inv" --format jpg --color gray --dpi 300Legal document archiving:
python scanner.py --output "D:\Legal\Cases\2024" --prefix "case_001" --format tiff --dpi 600 --color gray# Option 1: Direct execution with dotnet
dotnet run scanner.cs --output "D:\scans" --format jpg
# Option 2: Compile first, then run
dotnet build scanner.cs
./scanner --dpi 600 --color gray# Direct execution
python scanner.py --output "D:\scans" --format jpg
# Make executable (Linux/macOS)
chmod +x scanner.py
./scanner.py --dpi 600 --color gray# List available scanners
NAPS2.Console --driver wia --listdevices
NAPS2.Console --driver twain --listdevices
# Try different driver
python scanner.py --driver twain- Verify NAPS2 installation:
NAPS2.Console --version - Add NAPS2 to PATH environment variable
- Reinstall NAPS2 with default settings
C# Script:
- Ensure .NET 8 runtime is installed
- Check that
dotnetcommand is available in PATH
Python Script:
- Ensure Python 3.7+ is installed
- Check that
pythoncommand works in terminal
ADF/Feeder Problems:
# Try flatbed instead
python scanner.py --source glass
# Try TWAIN driver for better ADF support
python scanner.py --driver twain --source feederPoor Scan Quality:
# Increase DPI
python scanner.py --dpi 600
# Use uncompressed format
python scanner.py --format tiff- PNG - Best quality, lossless compression, moderate file size
- JPEG - Good quality, lossy compression, smallest file size
- TIFF - Professional quality, optional compression, large file size
- BMP - Uncompressed, largest file size, maximum quality
- PDF - Multi-page document format, good for archiving
- 75-150 DPI - Web use, email attachments
- 300 DPI - Standard document scanning, printing
- 600 DPI - High quality documents, small text
- 1200+ DPI - Professional archival, photography
- Modern .NET 8 - Top-level statements, async/await, nullable reference types
- Fast startup - Optimized for performance
- Cross-platform - Runs on Windows, macOS, Linux
- Python 3.7+ - Uses modern asyncio features
- Standard library only - No external dependencies
- Cross-platform - Works anywhere Python runs
- Identical behavior - Same parameters, same output, same error handling
- Async operations - Non-blocking I/O for better performance
- Automatic file detection - Verifies scan success by checking created files
- Real-time output - Shows NAPS2 progress during scanning
- Fork the repository
- Make your changes to the scripts
- Test with your scanner setup
- Submit a pull request
Both scripts should maintain identical functionality when changes are made.
This project is licensed under the MIT License.
- Issues: Report bugs and feature requests on GitHub
- NAPS2 Support: Visit https://www.naps2.com for NAPS2-specific issues
- Scanner Drivers: Contact your scanner manufacturer for driver support
