scan2form
v1.3.1
Published
Local offline bridge allowing web browsers to access physical scanners (WIA, TWAIN, SANE).
Maintainers
Readme
Scan2Form 🖨️ -> 🌐
Scan documents from a physical scanner directly into your web form.
Typically, browsers can't access scanners. Scan2Form solves this by running a tiny local bridge on your computer.
🚀 Quick Start for Developers
1. Install the package
npm install scan2form2. Add to your frontend code
import { Scan2Form } from 'scan2form';
const scanner = new Scan2Form();
// Triggers the scan and populates the input with the scanned file.
await scanner.scanToInput('my-input');🛠️ Handling Previews
Since scanToInput returns the file object, you can easily display a preview yourself:
const result = await scanner.scanToInput('my-input');
if (result.success) {
const url = URL.createObjectURL(result.file);
document.getElementById('my-preview-iframe').src = url;
}That's it! The file input is now populated with the scanned document, just as if the user uploaded it manually.
🖥️ Setup
To make scanning work, you need two things installed on your computer:
1. The Scanner Engine
We rely on a local scanning engine. You can use either NAPS2 (Recommended for Windows) or SANE (Recommended for macOS/Linux).
Option A: NAPS2 (Windows)
Download NAPS2 and install it.
Important: Ensure
naps2.consoleis available in your system PATH.How to configure NAPS2 Command Line
Tip (Windows PowerShell): You can set up an alias to make it simple:
function naps2.console { . "C:\Program Files\NAPS2\NAPS2.Console.exe" $args }
Option B: SANE (macOS / Linux)
- macOS: Install via Homebrew:
brew install sane-backends - Linux: Install via apt:
sudo apt-get install sane-utils - Verify installation by running
scanimage --versionin your terminal.
2. The Bridge Server
This tiny server listens for commands from your website.
# Run this command in your terminal
npx scan2form-server- Keep this running while scanning.
- It runs locally at
http://127.0.0.1:3000.
Alternative: We've included shortcut scripts in the package. If you have the files locally:
- Windows: Double-click
start-server.bat - Mac/Linux: Run
./start-server.sh
🛠️ System Requirements
- Node.js: v16+
- OS: Windows, Mac, or Linux
- Scanner: Any scanner supported by your OS drivers.
