Convert scanner image batches into one PDF
This commit is contained in:
1 parent
0bd598389f
commit
dce34df5cc
2 files changed
+37
-10
No files matched your search
@@ -16,11 +16,11 @@ The 20 Gi PVC uses `rook-cephfs-ec`, whose CephFS data pool is erasure coded wit
|
||||
|
||||
The [ScanservJS](https://sbs20.github.io/scanservjs/) web UI is at <https://scanner.brunner.ninja>. Point its DNS CNAME at the same target as `paper.brunner.ninja`. Traefik requires Authentik login and access to the **Paperless Users** group. The scanner's eSCL address is set once as `AIRSCAN_DEVICES` in `app.yaml`; update it there if the printer gets a new IP. The UI pulls scans directly from the HP OfficeJet Pro 8020 at `192.168.4.189:8080`, without HP cloud services or a running laptop.
|
||||
|
||||
Load the automatic document feeder, choose the HP scanner, its feeder source, **Auto** batch mode, and a **PDF** output format, then press **Scan**. The feeder batch becomes one multipage PDF. For one page, JPG and other Paperless-supported images also work. Review the staged result in the Files view, select its row, then choose **Action selected → Send to Paperless**. This moves the file into the existing Paperless consume directory; Paperless polls it every 30 seconds and handles OCR. The scan remains in staging until you send or delete it. ScanservJS does not offer reliable individual-page deletion or retry before sending: rescan the batch, or edit/split the PDF after import in Paperless. The OfficeJet Pro 8020's feeder is single-sided. This workflow starts scans from the web UI rather than a button on the printer panel.
|
||||
Load the automatic document feeder, choose the HP scanner and its feeder source, select **Auto** batch mode, then press **Scan**. Review the staged result in the Files view, select its row, then choose **Action selected → Send to Paperless**. ScanservJS may save a multipage JPG batch as one ZIP row; the action converts its ordered images into one multipage PDF before placing it in the existing Paperless consume directory. PDF and single-image results also work. Paperless polls the directory every 30 seconds and handles OCR. The scan remains in staging until you send or delete it. ScanservJS does not offer reliable individual-page deletion or retry before sending: rescan the batch, or edit/split the PDF after import in Paperless. The OfficeJet Pro 8020's feeder is single-sided. This workflow starts scans from the web UI rather than a button on the printer panel.
|
||||
|
||||
ScanservJS stores staged scans in the `scanner-staging` directory on the same retained CephFS claim. The deployment uses the pinned upstream image; its `config.local.js` action is in `app.yaml` and has a local handoff test in `test.sh`. The Authentik proxy application is created by `setup-authentik.sh` along with Paperless's OIDC application.
|
||||
|
||||
To merge Paperless documents imported from JPG scans, enable **Try to include archive version in merge for non-PDF files** in the merge dialog. Paperless's default merge tries to open the original JPG as a PDF and skips it. Enable **Delete original documents after successful merge** if you want only the merged entry in the active document list; the source entries go to Paperless's trash. For future multipage letters, choose a PDF output pipeline in ScanservJS before scanning.
|
||||
To merge separate Paperless documents imported from JPG scans, enable **Try to include archive version in merge for non-PDF files** in the merge dialog. Paperless's default merge tries to open the original JPG as a PDF and skips it. Enable **Delete original documents after successful merge** if you want only the merged entry in the active document list; the source entries go to Paperless's trash. A single feeder batch sent through the scanner action already becomes one document, without a later merge.
|
||||
|
||||
## CI/CD
|
||||
|
||||
|
||||
@@ -159,20 +159,47 @@ data:
|
||||
name: 'Send to Paperless',
|
||||
async execute(fileInfo) {
|
||||
const source = await fs.realpath(fileInfo.fullname);
|
||||
const supported = new Set(['.pdf', '.jpg', '.jpeg', '.png', '.tif', '.tiff', '.gif', '.webp']);
|
||||
if (!source.startsWith(output + '/') || !supported.has(path.extname(source).toLowerCase())) {
|
||||
throw new Error('Only staged PDFs and images supported by Paperless can be sent');
|
||||
const images = new Set(['.jpg', '.jpeg', '.png', '.tif', '.tiff', '.gif', '.webp']);
|
||||
const extension = path.extname(source).toLowerCase();
|
||||
if (!source.startsWith(output + '/') || !(['.pdf', '.zip'].includes(extension) || images.has(extension))) {
|
||||
throw new Error('Only staged PDFs, images, and image ZIPs can be sent');
|
||||
}
|
||||
const name = `${Date.now()}-${crypto.randomBytes(6).toString('hex')}-${path.basename(source)}`;
|
||||
const destination = path.join(consume, name);
|
||||
const pending = destination + '.part';
|
||||
let upload = source;
|
||||
let temp;
|
||||
let name = path.basename(source);
|
||||
let pending;
|
||||
try {
|
||||
await fs.copyFile(source, pending);
|
||||
if (extension === '.zip') {
|
||||
const AdmZip = require(require.resolve('adm-zip', {paths: ['/usr/lib/scanservjs']}));
|
||||
const entries = new AdmZip(source).getEntries();
|
||||
if (entries.length === 0 || entries.some(entry =>
|
||||
entry.isDirectory || entry.entryName !== path.basename(entry.entryName) ||
|
||||
!images.has(path.extname(entry.entryName).toLowerCase()))) {
|
||||
throw new Error('ZIP must contain only scanned image pages');
|
||||
}
|
||||
temp = await fs.mkdtemp('/tmp/paperless-scan-');
|
||||
const inputs = [];
|
||||
for (const [index, entry] of entries.entries()) {
|
||||
const input = path.join(temp, `${String(index).padStart(4, '0')}${path.extname(entry.entryName)}`);
|
||||
await fs.writeFile(input, entry.getData());
|
||||
inputs.push(input);
|
||||
}
|
||||
upload = path.join(temp, 'merged.pdf');
|
||||
const {execFile} = require('node:child_process');
|
||||
const {promisify} = require('node:util');
|
||||
await promisify(execFile)('convert', [...inputs, upload]);
|
||||
name = path.basename(source, path.extname(source)) + '.pdf';
|
||||
}
|
||||
const destination = path.join(consume, `${Date.now()}-${crypto.randomBytes(6).toString('hex')}-${name}`);
|
||||
pending = destination + '.part';
|
||||
await fs.copyFile(upload, pending);
|
||||
await fs.rename(pending, destination);
|
||||
await fs.unlink(source);
|
||||
} catch (error) {
|
||||
await fs.rm(pending, {force: true});
|
||||
if (pending) await fs.rm(pending, {force: true});
|
||||
throw error;
|
||||
} finally {
|
||||
if (temp) await fs.rm(temp, {recursive: true, force: true});
|
||||
}
|
||||
},
|
||||
}],
|
||||
|
||||
Reference in new issue
Block a user