Files
2026-10-10 01:17:31 -04:00

88 lines
3.9 KiB
Markdown

# scan-station
Scan-to-Paperless for a Fujitsu ScanSnap iX500 attached to a Linux VM (Proxmox USB passthrough).
Load paper (or press the scan button) and the pages are scanned duplex, compressed, stripped of blank pages, and uploaded to Paperless-ngx.
## How it works
```
iX500 (USB) -> scanbd (polls button + page-loaded sensor)
-> scan.sh: scanimage -> JPEG -> blank filter -> img2pdf -> Paperless API
```
- **Triggers:** scan button (`scan` action) and paper loaded in the feeder (`pageloaded` action, 3 s settle delay).
- **Blank pages:** pages below `BLANK_THRESHOLD` ink are left out of the upload. A full copy of every scan (blanks included) is kept in `/var/lib/scan-station/archive`.
- **Barcode splitting:** patch sheets work with Paperless barcode separators. The blank back of a patch sheet is dropped by the blank filter, the barcode front is consumed by Paperless.
- **Failures:** if an upload fails, the PDF is saved to `/var/lib/scan-station/failed`.
- **Cleanup:** a daily cron job deletes archive files older than 60 days.
## Layout
| Path | Installed to |
|---|---|
| `scripts/scan.sh` | `/etc/scanbd/scripts/scan.sh` |
| `config/env.example` | `/etc/scan-station/env` (copy, then edit) |
| `config/scanbd-actions.conf` | merge into `/etc/scanbd/scanbd.conf` |
| `config/scan-station-cleanup.cron` | `/etc/cron.d/scan-station-cleanup` |
| `install.sh` | helper that does the above (except the scanbd.conf merge) |
## Setup
1. **Proxmox:** pass the scanner through to the VM (`qm set <vmid> -usb0 host=<vendor:product>`; get IDs from `lsusb`).
2. **Packages (VM):**
```bash
sudo apt install sane-utils scanbd img2pdf imagemagick curl
```
3. **SANE config.** On this Ubuntu install scanbd uses `/etc/scanbd` as its SANE config dir (`SANE_CONFIG_DIR` in `scanbd.conf`).
```bash
echo net | sudo tee /etc/sane.d/dll.conf
echo localhost | sudo tee /etc/sane.d/net.conf
echo fujitsu | sudo tee /etc/scanbd/dll.conf
```
4. **Permissions:** `saned` must be in the `scanner` group (`sudo usermod -aG scanner saned`).
5. **Install the files:**
```bash
sudo ./install.sh
sudo nano /etc/scan-station/env # set PAPERLESS_TOKEN
```
6. **scanbd actions:** replace the `action scan { ... }` block in `/etc/scanbd/scanbd.conf` with the blocks in `config/scanbd-actions.conf`. Comment out the other default actions (copy, email, file).
7. **Start:**
```bash
sudo systemctl enable --now scanbd
sudo systemctl restart scanbd
```
## Config (`/etc/scan-station/env`)
| Variable | Meaning |
|---|---|
| `PAPERLESS_URL` | Base URL of Paperless-ngx |
| `PAPERLESS_TOKEN` | API token (dedicated user recommended) |
| `RESOLUTION` | Scan DPI (200 is plenty for OCR) |
| `ROTATE` | `0` or `180` if scans come out upside down |
| `BLANK_THRESHOLD` | Ink fraction below which a page counts as blank (default `0.003`) |
## Operations
```bash
journalctl -t scan-station -n 30 --no-pager # script log (shows skipped blanks + ink values)
journalctl -u scanbd -n 50 --no-pager # scanbd log
scanimage -L # lists device via scanbd
```
## Notes and gotchas
- scanbd owns the USB device. Run `sudo systemctl stop scanbd` before using `scanimage -d fujitsu` directly.
- Large uploads through a reverse proxy need a raised body limit. For Nginx Proxy Manager, add in the proxy host's Advanced tab:
```nginx
client_max_body_size 500m;
proxy_request_buffering off;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
client_body_timeout 300s;
```
Cloudflare's free plan caps uploads at 100 MB (413); JPEG compression keeps files well under that.
- The paper-loaded trigger needs a 0 to 1 transition. Remove and reload paper if scanbd started with paper already in the feeder.
- Duplex backs flipped but fronts fine? Rotate even-numbered pages with `mogrify -rotate 180 "$WORK"/p_*[02468].*` before the PDF step.
- Never commit the real `env` file (it is in `.gitignore`).