node-hp-scan-to 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -27
- package/dist/Destination.js +2 -2
- package/dist/Destination.js.map +1 -1
- package/dist/DiscoveryTree.js.map +1 -1
- package/dist/Event.js.map +1 -1
- package/dist/EventTable.js +1 -1
- package/dist/EventTable.js.map +1 -1
- package/dist/HPApi.js +4 -4
- package/dist/HPApi.js.map +1 -1
- package/dist/InputSource.js +1 -1
- package/dist/InputSource.js.map +1 -1
- package/dist/Job.js +2 -2
- package/dist/Job.js.map +1 -1
- package/dist/JpegUtil.d.ts +1 -0
- package/dist/JpegUtil.js.map +1 -1
- package/dist/PaperlessCOnfig.d.ts +7 -0
- package/dist/PaperlessCOnfig.js +3 -0
- package/dist/PaperlessCOnfig.js.map +1 -0
- package/dist/PaperlessConfig.d.ts +7 -0
- package/dist/PaperlessConfig.js +3 -0
- package/dist/PaperlessConfig.js.map +1 -0
- package/dist/PathHelper.js.map +1 -1
- package/dist/ScanCaps.js +12 -2
- package/dist/ScanCaps.js.map +1 -1
- package/dist/ScanContent.d.ts +0 -1
- package/dist/ScanContent.js +0 -24
- package/dist/ScanContent.js.map +1 -1
- package/dist/ScanJobManifest.js.map +1 -1
- package/dist/ScanJobSettings.js +2 -2
- package/dist/ScanJobSettings.js.map +1 -1
- package/dist/ScanStatus.js.map +1 -1
- package/dist/WalkupScanDestination.js.map +1 -1
- package/dist/WalkupScanDestinations.js +1 -1
- package/dist/WalkupScanDestinations.js.map +1 -1
- package/dist/WalkupScanManifest.js.map +1 -1
- package/dist/WalkupScanToCompDestination.js.map +1 -1
- package/dist/WalkupScanToCompDestinations.js +1 -1
- package/dist/WalkupScanToCompDestinations.js.map +1 -1
- package/dist/WalkupScanToCompManifest.js.map +1 -1
- package/dist/commitInfo.json +3 -0
- package/dist/healthcheck.d.ts +1 -0
- package/dist/healthcheck.js +24 -0
- package/dist/healthcheck.js.map +1 -0
- package/dist/index.js +105 -18
- package/dist/index.js.map +1 -1
- package/dist/listening.js +2 -2
- package/dist/listening.js.map +1 -1
- package/dist/paperless/PaperlessConfig.d.ts +7 -0
- package/dist/paperless/PaperlessConfig.js +3 -0
- package/dist/paperless/PaperlessConfig.js.map +1 -0
- package/dist/paperless/paperless.d.ts +7 -0
- package/dist/paperless/paperless.js +83 -0
- package/dist/paperless/paperless.js.map +1 -0
- package/dist/paperless.d.ts +7 -0
- package/dist/paperless.js +83 -0
- package/dist/paperless.js.map +1 -0
- package/dist/pdfProcessing.d.ts +4 -0
- package/dist/pdfProcessing.js +52 -0
- package/dist/pdfProcessing.js.map +1 -0
- package/dist/postProcessing.d.ts +3 -0
- package/dist/postProcessing.js +44 -0
- package/dist/postProcessing.js.map +1 -0
- package/dist/readDeviceCapabilities.js.map +1 -1
- package/dist/scanProcessing.d.ts +7 -1
- package/dist/scanProcessing.js +20 -49
- package/dist/scanProcessing.js.map +1 -1
- package/dist/test/PathHelper.test.js +2 -2
- package/dist/test/PathHelper.test.js.map +1 -1
- package/dist/test/ScanCaps.test.js +20 -0
- package/dist/test/ScanCaps.test.js.map +1 -1
- package/dist/test/clean.js.map +1 -1
- package/dist/test/scanProcessing.test.js +1 -0
- package/dist/test/scanProcessing.test.js.map +1 -1
- package/dist/test-bonjour.d.ts +1 -0
- package/dist/test-bonjour.js +20 -0
- package/dist/test-bonjour.js.map +1 -0
- package/package.json +12 -9
- package/src/Destination.ts +2 -2
- package/src/EventTable.ts +1 -1
- package/src/HPApi.ts +4 -4
- package/src/Job.ts +2 -2
- package/src/ScanCaps.ts +18 -8
- package/src/ScanContent.ts +0 -22
- package/src/ScanJobSettings.ts +2 -2
- package/src/WalkupScanDestinations.ts +1 -1
- package/src/WalkupScanToCompDestinations.ts +1 -1
- package/src/commitInfo.json +3 -0
- package/src/healthcheck.ts +17 -0
- package/src/index.ts +131 -23
- package/src/listening.ts +2 -2
- package/src/paperless/PaperlessConfig.ts +7 -0
- package/src/paperless/paperless.ts +122 -0
- package/src/pdfProcessing.ts +67 -0
- package/src/postProcessing.ts +91 -0
- package/src/scanProcessing.ts +46 -93
package/src/listening.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { DeviceCapabilities } from "./DeviceCapabilities";
|
|
|
6
6
|
export async function waitScanRequest(compEventURI: string): Promise<boolean> {
|
|
7
7
|
const waitMax = 50;
|
|
8
8
|
for (let i = 0; i < waitMax; i++) {
|
|
9
|
-
|
|
9
|
+
const walkupScanToCompEvent =
|
|
10
10
|
await HPApi.getWalkupScanToCompEvent(compEventURI);
|
|
11
|
-
|
|
11
|
+
const message = walkupScanToCompEvent.eventType;
|
|
12
12
|
if (message === "HostSelected") {
|
|
13
13
|
// this ok to wait
|
|
14
14
|
} else if (message === "ScanRequested") {
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import fsSync from "fs";
|
|
2
|
+
import FormData from "form-data";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import { ScanConfig } from "../scanProcessing";
|
|
5
|
+
import { ScanContent } from "../ScanContent";
|
|
6
|
+
import fs from "fs/promises";
|
|
7
|
+
import { convertToPdf, mergeToPdf } from "../pdfProcessing";
|
|
8
|
+
import { PaperlessConfig } from "./PaperlessConfig";
|
|
9
|
+
|
|
10
|
+
export async function uploadImagesAsSeparateDocumentsToPaperless(
|
|
11
|
+
scanJobContent: ScanContent,
|
|
12
|
+
paperlessConfig: PaperlessConfig,
|
|
13
|
+
) {
|
|
14
|
+
for (let i = 0; i < scanJobContent.elements.length; ++i) {
|
|
15
|
+
const filePath = scanJobContent.elements[i].path;
|
|
16
|
+
await uploadToPaperless(filePath, paperlessConfig);
|
|
17
|
+
if (!paperlessConfig.keepFiles) {
|
|
18
|
+
await fs.unlink(filePath);
|
|
19
|
+
console.log(
|
|
20
|
+
`Image document ${filePath} has been removed from the filesystem`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function convertImagesToPdfAndUploadAsSeparateDocumentsToPaperless(
|
|
27
|
+
scanJobContent: ScanContent,
|
|
28
|
+
paperlessConfig: PaperlessConfig,
|
|
29
|
+
) {
|
|
30
|
+
for (let i = 0; i < scanJobContent.elements.length; ++i) {
|
|
31
|
+
const pdfFilePath = await convertToPdf(
|
|
32
|
+
scanJobContent.elements[i],
|
|
33
|
+
!paperlessConfig.keepFiles,
|
|
34
|
+
);
|
|
35
|
+
if (pdfFilePath) {
|
|
36
|
+
await uploadToPaperless(pdfFilePath, paperlessConfig);
|
|
37
|
+
await fs.unlink(pdfFilePath);
|
|
38
|
+
} else {
|
|
39
|
+
console.log(
|
|
40
|
+
"Pdf generation has failed, nothing is going to be uploaded to paperless for: " +
|
|
41
|
+
scanJobContent.elements[i].path,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function mergeToPdfAndUploadAsSingleDocumentToPaperless(
|
|
48
|
+
folder: string,
|
|
49
|
+
scanCount: number,
|
|
50
|
+
scanJobContent: ScanContent,
|
|
51
|
+
scanConfig: ScanConfig,
|
|
52
|
+
scanDate: Date,
|
|
53
|
+
paperlessConfig: PaperlessConfig,
|
|
54
|
+
) {
|
|
55
|
+
const pdfFilePath = await mergeToPdf(
|
|
56
|
+
folder,
|
|
57
|
+
scanCount,
|
|
58
|
+
scanJobContent,
|
|
59
|
+
scanConfig.directoryConfig.filePattern,
|
|
60
|
+
scanDate,
|
|
61
|
+
!paperlessConfig.keepFiles,
|
|
62
|
+
);
|
|
63
|
+
if (pdfFilePath) {
|
|
64
|
+
await uploadToPaperless(pdfFilePath, paperlessConfig);
|
|
65
|
+
await fs.unlink(pdfFilePath);
|
|
66
|
+
console.log(
|
|
67
|
+
`Pdf document ${pdfFilePath} has been removed from the filesystem`,
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
console.log(
|
|
71
|
+
"Pdf generation has failed, nothing is going to be uploaded to paperless",
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function uploadPdfToPaperless(
|
|
77
|
+
pdfFilePath: string | null,
|
|
78
|
+
paperlessConfig: PaperlessConfig,
|
|
79
|
+
) {
|
|
80
|
+
if (pdfFilePath) {
|
|
81
|
+
await uploadToPaperless(pdfFilePath, paperlessConfig);
|
|
82
|
+
if (!paperlessConfig.keepFiles) {
|
|
83
|
+
await fs.unlink(pdfFilePath);
|
|
84
|
+
console.log(
|
|
85
|
+
`Pdf document ${pdfFilePath} has been removed from the filesystem`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
console.log(
|
|
90
|
+
"Pdf generation has failed, nothing is going to be uploaded to paperless",
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function uploadToPaperless(
|
|
96
|
+
filePath: string,
|
|
97
|
+
paperlessConfig: PaperlessConfig,
|
|
98
|
+
): Promise<void> {
|
|
99
|
+
const url = paperlessConfig.postDocumentUrl;
|
|
100
|
+
|
|
101
|
+
const authToken = paperlessConfig.authToken;
|
|
102
|
+
|
|
103
|
+
const fileStream = fsSync.createReadStream(filePath);
|
|
104
|
+
|
|
105
|
+
const form = new FormData();
|
|
106
|
+
form.append("document", fileStream);
|
|
107
|
+
|
|
108
|
+
console.log(`Start uploading to paperless: ${filePath}`);
|
|
109
|
+
try {
|
|
110
|
+
const response = await axios.post(url, form, {
|
|
111
|
+
headers: {
|
|
112
|
+
...form.getHeaders(),
|
|
113
|
+
Authorization: `Token ${authToken}`,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
console.log("Document successfully uploaded to paperless:", response.data);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error("Fail to upload document:", error);
|
|
120
|
+
}
|
|
121
|
+
fileStream.close();
|
|
122
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ScanContent, ScanPage } from "./ScanContent";
|
|
2
|
+
import PathHelper from "./PathHelper";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { jsPDF } from "jspdf";
|
|
6
|
+
|
|
7
|
+
export async function mergeToPdf(
|
|
8
|
+
folder: string,
|
|
9
|
+
scanCount: number,
|
|
10
|
+
scanJobContent: ScanContent,
|
|
11
|
+
filePattern: string | undefined,
|
|
12
|
+
date: Date,
|
|
13
|
+
deleteFiles: boolean,
|
|
14
|
+
): Promise<string | null> {
|
|
15
|
+
if (scanJobContent.elements.length > 0) {
|
|
16
|
+
const pdfFilePath: string = PathHelper.getFileForScan(
|
|
17
|
+
folder,
|
|
18
|
+
scanCount,
|
|
19
|
+
filePattern,
|
|
20
|
+
"pdf",
|
|
21
|
+
date,
|
|
22
|
+
);
|
|
23
|
+
await createPdfFrom(scanJobContent, pdfFilePath);
|
|
24
|
+
if (deleteFiles) {
|
|
25
|
+
await Promise.all(scanJobContent.elements.map((e) => fs.unlink(e.path)));
|
|
26
|
+
}
|
|
27
|
+
return pdfFilePath;
|
|
28
|
+
}
|
|
29
|
+
console.log(`No page available to build a pdf file`);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function convertToPdf(
|
|
34
|
+
scanPage: ScanPage,
|
|
35
|
+
deleteFile: boolean,
|
|
36
|
+
): Promise<string | null> {
|
|
37
|
+
const fileName = path.basename(scanPage.path, path.extname(scanPage.path));
|
|
38
|
+
const pdfFilePath = path.join(path.dirname(scanPage.path), `${fileName}.pdf`);
|
|
39
|
+
|
|
40
|
+
await createPdfFrom({ elements: [scanPage] }, pdfFilePath);
|
|
41
|
+
if (deleteFile) {
|
|
42
|
+
await fs.unlink(scanPage.path);
|
|
43
|
+
}
|
|
44
|
+
return pdfFilePath;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function createPdfFrom(
|
|
48
|
+
scanContent: ScanContent,
|
|
49
|
+
destination: string,
|
|
50
|
+
) {
|
|
51
|
+
let doc: jsPDF | null = null;
|
|
52
|
+
for (const element of scanContent.elements) {
|
|
53
|
+
const widthInInches = element.width / element.xResolution;
|
|
54
|
+
const heightInInches = element.height / element.yResolution;
|
|
55
|
+
const format = [widthInInches, heightInInches];
|
|
56
|
+
|
|
57
|
+
if (doc == null) {
|
|
58
|
+
doc = new jsPDF({ unit: "in", floatPrecision: 3, format });
|
|
59
|
+
} else {
|
|
60
|
+
doc.addPage(format);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const imageByteBuffer = await fs.readFile(element.path);
|
|
64
|
+
doc.addImage(imageByteBuffer, "JPEG", 0, 0, widthInInches, heightInInches);
|
|
65
|
+
}
|
|
66
|
+
doc?.save(destination);
|
|
67
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ScanContent } from "./ScanContent";
|
|
2
|
+
import { mergeToPdf } from "./pdfProcessing";
|
|
3
|
+
import {
|
|
4
|
+
convertImagesToPdfAndUploadAsSeparateDocumentsToPaperless,
|
|
5
|
+
mergeToPdfAndUploadAsSingleDocumentToPaperless,
|
|
6
|
+
uploadImagesAsSeparateDocumentsToPaperless,
|
|
7
|
+
uploadPdfToPaperless,
|
|
8
|
+
} from "./paperless/paperless";
|
|
9
|
+
import { ScanConfig } from "./scanProcessing";
|
|
10
|
+
|
|
11
|
+
export async function postProcessing(
|
|
12
|
+
scanConfig: ScanConfig,
|
|
13
|
+
folder: string,
|
|
14
|
+
tempFolder: string,
|
|
15
|
+
scanCount: number,
|
|
16
|
+
scanJobContent: ScanContent,
|
|
17
|
+
scanDate: Date,
|
|
18
|
+
toPdf: boolean,
|
|
19
|
+
) {
|
|
20
|
+
const paperlessConfig = scanConfig.paperlessConfig;
|
|
21
|
+
if (toPdf) {
|
|
22
|
+
const pdfFilePath = await mergeToPdf(
|
|
23
|
+
paperlessConfig ? tempFolder : folder,
|
|
24
|
+
scanCount,
|
|
25
|
+
scanJobContent,
|
|
26
|
+
scanConfig.directoryConfig.filePattern,
|
|
27
|
+
scanDate,
|
|
28
|
+
true,
|
|
29
|
+
);
|
|
30
|
+
displayPdfScan(pdfFilePath, scanJobContent);
|
|
31
|
+
if (paperlessConfig) {
|
|
32
|
+
await uploadPdfToPaperless(pdfFilePath, paperlessConfig);
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
displayJpegScan(scanJobContent);
|
|
36
|
+
if (paperlessConfig) {
|
|
37
|
+
if (paperlessConfig.groupMultiPageScanIntoAPdf) {
|
|
38
|
+
await mergeToPdfAndUploadAsSingleDocumentToPaperless(
|
|
39
|
+
folder,
|
|
40
|
+
scanCount,
|
|
41
|
+
scanJobContent,
|
|
42
|
+
scanConfig,
|
|
43
|
+
scanDate,
|
|
44
|
+
paperlessConfig,
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
if (paperlessConfig.alwaysSendAsPdfFile) {
|
|
48
|
+
await convertImagesToPdfAndUploadAsSeparateDocumentsToPaperless(
|
|
49
|
+
scanJobContent,
|
|
50
|
+
paperlessConfig,
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
await uploadImagesAsSeparateDocumentsToPaperless(
|
|
54
|
+
scanJobContent,
|
|
55
|
+
paperlessConfig,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function displayPdfScan(
|
|
64
|
+
pdfFilePath: string | null,
|
|
65
|
+
scanJobContent: ScanContent,
|
|
66
|
+
) {
|
|
67
|
+
if (pdfFilePath === null) {
|
|
68
|
+
console.log(`Pdf generated has not been generated`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(
|
|
72
|
+
`The following page(s) have been rendered inside '${pdfFilePath}': `,
|
|
73
|
+
);
|
|
74
|
+
scanJobContent.elements.forEach((e) =>
|
|
75
|
+
console.log(
|
|
76
|
+
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
77
|
+
e.height
|
|
78
|
+
}`,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function displayJpegScan(scanJobContent: ScanContent) {
|
|
84
|
+
scanJobContent.elements.forEach((e) =>
|
|
85
|
+
console.log(
|
|
86
|
+
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
87
|
+
e.height
|
|
88
|
+
} - ${e.path}`,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
}
|
package/src/scanProcessing.ts
CHANGED
|
@@ -7,12 +7,14 @@ import JpegUtil from "./JpegUtil";
|
|
|
7
7
|
import { DeviceCapabilities } from "./DeviceCapabilities";
|
|
8
8
|
import { waitForScanEvent, waitScanRequest } from "./listening";
|
|
9
9
|
import ScanJobSettings from "./ScanJobSettings";
|
|
10
|
-
import {
|
|
10
|
+
import { ScanContent, ScanPage } from "./ScanContent";
|
|
11
11
|
import Job from "./Job";
|
|
12
12
|
import { delay } from "./delay";
|
|
13
13
|
import PathHelper from "./PathHelper";
|
|
14
14
|
import ScanStatus from "./ScanStatus";
|
|
15
15
|
import { InputSource } from "./InputSource";
|
|
16
|
+
import { PaperlessConfig } from "./paperless/PaperlessConfig";
|
|
17
|
+
import { postProcessing } from "./postProcessing";
|
|
16
18
|
|
|
17
19
|
async function waitDeviceUntilItIsReadyToUploadOrCompleted(
|
|
18
20
|
jobUrl: string,
|
|
@@ -38,7 +40,7 @@ async function waitDeviceUntilItIsReadyToUploadOrCompleted(
|
|
|
38
40
|
return job;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
async function
|
|
43
|
+
async function tryGetDestination(
|
|
42
44
|
event: Event,
|
|
43
45
|
): Promise<WalkupScanDestination | WalkupScanToCompDestination | null> {
|
|
44
46
|
//this code can in some cases be executed before the user actually chooses between Document or Photo
|
|
@@ -71,7 +73,7 @@ async function TryGetDestination(
|
|
|
71
73
|
async function scanProcessing(filePath: string): Promise<number | null> {
|
|
72
74
|
const buffer: Buffer = await fs.readFile(filePath);
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
const height = JpegUtil.fixSizeWithDNL(buffer);
|
|
75
77
|
if (height != null) {
|
|
76
78
|
// rewrite the fixed file
|
|
77
79
|
await fs.writeFile(filePath, buffer);
|
|
@@ -86,7 +88,7 @@ function createScanPage(
|
|
|
86
88
|
filePath: string,
|
|
87
89
|
sizeFixed: number | null,
|
|
88
90
|
): ScanPage {
|
|
89
|
-
|
|
91
|
+
const height = sizeFixed ?? job.imageHeight;
|
|
90
92
|
return {
|
|
91
93
|
path: filePath,
|
|
92
94
|
pageNumber: currentPageNumber,
|
|
@@ -97,7 +99,7 @@ function createScanPage(
|
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
async function
|
|
102
|
+
async function handleScanProcessingState(
|
|
101
103
|
job: Job,
|
|
102
104
|
inputSource: InputSource,
|
|
103
105
|
folder: string,
|
|
@@ -168,7 +170,7 @@ async function executeScanJob(
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
if (job.jobState === "Processing") {
|
|
171
|
-
const page = await
|
|
173
|
+
const page = await handleScanProcessingState(
|
|
172
174
|
job,
|
|
173
175
|
inputSource,
|
|
174
176
|
folder,
|
|
@@ -201,9 +203,9 @@ async function waitScanNewPageRequest(compEventURI: string): Promise<boolean> {
|
|
|
201
203
|
while (wait) {
|
|
202
204
|
await new Promise((resolve) => setTimeout(resolve, 1000)); //wait 1s
|
|
203
205
|
|
|
204
|
-
|
|
206
|
+
const walkupScanToCompEvent =
|
|
205
207
|
await HPApi.getWalkupScanToCompEvent(compEventURI);
|
|
206
|
-
|
|
208
|
+
const message = walkupScanToCompEvent.eventType;
|
|
207
209
|
|
|
208
210
|
if (message === "ScanNewPageRequested") {
|
|
209
211
|
startNewScanJob = true;
|
|
@@ -281,59 +283,6 @@ async function executeScanJobs(
|
|
|
281
283
|
}
|
|
282
284
|
}
|
|
283
285
|
|
|
284
|
-
async function mergeToPdf(
|
|
285
|
-
folder: string,
|
|
286
|
-
scanCount: number,
|
|
287
|
-
scanJobContent: ScanContent,
|
|
288
|
-
filePattern: string | undefined,
|
|
289
|
-
date: Date,
|
|
290
|
-
): Promise<string | null> {
|
|
291
|
-
if (scanJobContent.elements.length > 0) {
|
|
292
|
-
const pdfFilePath: string = PathHelper.getFileForScan(
|
|
293
|
-
folder,
|
|
294
|
-
scanCount,
|
|
295
|
-
filePattern,
|
|
296
|
-
"pdf",
|
|
297
|
-
date,
|
|
298
|
-
);
|
|
299
|
-
await createPdfFrom(scanJobContent, pdfFilePath);
|
|
300
|
-
scanJobContent.elements.forEach((e) => fs.unlink(e.path));
|
|
301
|
-
return pdfFilePath;
|
|
302
|
-
}
|
|
303
|
-
console.log(`No page available to build a pdf file`);
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function displayPdfScan(
|
|
308
|
-
pdfFilePath: string | null,
|
|
309
|
-
scanJobContent: ScanContent,
|
|
310
|
-
) {
|
|
311
|
-
if (pdfFilePath === null) {
|
|
312
|
-
console.log(`Pdf generated has not been generated`);
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
console.log(
|
|
316
|
-
`The following page(s) have been rendered inside '${pdfFilePath}': `,
|
|
317
|
-
);
|
|
318
|
-
scanJobContent.elements.forEach((e) =>
|
|
319
|
-
console.log(
|
|
320
|
-
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
321
|
-
e.height
|
|
322
|
-
}`,
|
|
323
|
-
),
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function displayJpegScan(scanJobContent: ScanContent) {
|
|
328
|
-
scanJobContent.elements.forEach((e) =>
|
|
329
|
-
console.log(
|
|
330
|
-
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
331
|
-
e.height
|
|
332
|
-
} - ${e.path}`,
|
|
333
|
-
),
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
286
|
function isPdf(
|
|
338
287
|
destination: WalkupScanDestination | WalkupScanToCompDestination,
|
|
339
288
|
) {
|
|
@@ -360,7 +309,7 @@ export function getScanWidth(
|
|
|
360
309
|
scanConfig: ScanConfig,
|
|
361
310
|
inputSource: InputSource,
|
|
362
311
|
deviceCapabilities: DeviceCapabilities,
|
|
363
|
-
) {
|
|
312
|
+
): number | null {
|
|
364
313
|
if (scanConfig.width && scanConfig.width > 0) {
|
|
365
314
|
const maxWidth =
|
|
366
315
|
inputSource === InputSource.Adf
|
|
@@ -373,7 +322,9 @@ export function getScanWidth(
|
|
|
373
322
|
return scanConfig.width;
|
|
374
323
|
}
|
|
375
324
|
} else {
|
|
376
|
-
return
|
|
325
|
+
return inputSource === InputSource.Adf
|
|
326
|
+
? deviceCapabilities.adfMaxWidth
|
|
327
|
+
: deviceCapabilities.platenMaxWidth;
|
|
377
328
|
}
|
|
378
329
|
}
|
|
379
330
|
|
|
@@ -381,7 +332,7 @@ export function getScanHeight(
|
|
|
381
332
|
scanConfig: ScanConfig,
|
|
382
333
|
inputSource: InputSource,
|
|
383
334
|
deviceCapabilities: DeviceCapabilities,
|
|
384
|
-
) {
|
|
335
|
+
): number | null {
|
|
385
336
|
if (scanConfig.height && scanConfig.height > 0) {
|
|
386
337
|
const maxHeight =
|
|
387
338
|
inputSource === InputSource.Adf
|
|
@@ -394,11 +345,13 @@ export function getScanHeight(
|
|
|
394
345
|
return scanConfig.height;
|
|
395
346
|
}
|
|
396
347
|
} else {
|
|
397
|
-
return
|
|
348
|
+
return inputSource === InputSource.Adf
|
|
349
|
+
? deviceCapabilities.adfMaxHeight
|
|
350
|
+
: deviceCapabilities.platenMaxHeight;
|
|
398
351
|
}
|
|
399
352
|
}
|
|
400
353
|
|
|
401
|
-
export async function
|
|
354
|
+
export async function saveScanFromEvent(
|
|
402
355
|
event: Event,
|
|
403
356
|
folder: string,
|
|
404
357
|
tempFolder: string,
|
|
@@ -413,7 +366,7 @@ export async function saveScan(
|
|
|
413
366
|
}
|
|
414
367
|
}
|
|
415
368
|
|
|
416
|
-
const destination = await
|
|
369
|
+
const destination = await tryGetDestination(event);
|
|
417
370
|
if (!destination) {
|
|
418
371
|
console.log("No shortcut selected!");
|
|
419
372
|
return;
|
|
@@ -443,7 +396,7 @@ export async function saveScan(
|
|
|
443
396
|
const scanStatus = await HPApi.getScanStatus();
|
|
444
397
|
|
|
445
398
|
if (scanStatus.scannerState !== "Idle") {
|
|
446
|
-
console.log("Scanner state is not Idle, aborting scan attempt...!")
|
|
399
|
+
console.log("Scanner state is not Idle, aborting scan attempt...!");
|
|
447
400
|
}
|
|
448
401
|
|
|
449
402
|
console.log("Afd is : " + scanStatus.adfState);
|
|
@@ -479,19 +432,15 @@ export async function saveScan(
|
|
|
479
432
|
console.log(
|
|
480
433
|
`Scan of page(s) completed totalPages: ${scanJobContent.elements.length}:`,
|
|
481
434
|
);
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
displayPdfScan(pdfFilePath, scanJobContent);
|
|
492
|
-
} else {
|
|
493
|
-
displayJpegScan(scanJobContent);
|
|
494
|
-
}
|
|
435
|
+
await postProcessing(
|
|
436
|
+
scanConfig,
|
|
437
|
+
folder,
|
|
438
|
+
tempFolder,
|
|
439
|
+
scanCount,
|
|
440
|
+
scanJobContent,
|
|
441
|
+
scanDate,
|
|
442
|
+
toPdf,
|
|
443
|
+
);
|
|
495
444
|
}
|
|
496
445
|
|
|
497
446
|
export type DirectoryConfig = {
|
|
@@ -499,11 +448,13 @@ export type DirectoryConfig = {
|
|
|
499
448
|
tempDirectory: string | undefined;
|
|
500
449
|
filePattern: string | undefined;
|
|
501
450
|
};
|
|
451
|
+
|
|
502
452
|
export type ScanConfig = {
|
|
503
453
|
resolution: number;
|
|
504
454
|
width: number | null;
|
|
505
455
|
height: number | null;
|
|
506
456
|
directoryConfig: DirectoryConfig;
|
|
457
|
+
paperlessConfig: PaperlessConfig | undefined;
|
|
507
458
|
};
|
|
508
459
|
export type AdfAutoScanConfig = ScanConfig & {
|
|
509
460
|
isDuplex: boolean;
|
|
@@ -512,6 +463,11 @@ export type AdfAutoScanConfig = ScanConfig & {
|
|
|
512
463
|
startScanDelay: number;
|
|
513
464
|
};
|
|
514
465
|
|
|
466
|
+
export type SingleScanConfig = ScanConfig & {
|
|
467
|
+
isDuplex: boolean;
|
|
468
|
+
generatePdf: boolean;
|
|
469
|
+
};
|
|
470
|
+
|
|
515
471
|
export async function scanFromAdf(
|
|
516
472
|
scanCount: number,
|
|
517
473
|
folder: string,
|
|
@@ -568,18 +524,15 @@ export async function scanFromAdf(
|
|
|
568
524
|
`Scan of page(s) completed, total pages: ${scanJobContent.elements.length}:`,
|
|
569
525
|
);
|
|
570
526
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
} else {
|
|
581
|
-
displayJpegScan(scanJobContent);
|
|
582
|
-
}
|
|
527
|
+
await postProcessing(
|
|
528
|
+
adfAutoScanConfig,
|
|
529
|
+
folder,
|
|
530
|
+
tempFolder,
|
|
531
|
+
scanCount,
|
|
532
|
+
scanJobContent,
|
|
533
|
+
date,
|
|
534
|
+
adfAutoScanConfig.generatePdf,
|
|
535
|
+
);
|
|
583
536
|
}
|
|
584
537
|
|
|
585
538
|
export async function waitAdfLoaded(
|