@pallasoft/ps-file-components 1.4.0 → 2.0.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/dist/components/ps-document-scanner-loader.d.ts +1 -1
- package/dist/components/ps-document-scanner-sheet.d.ts +1 -1
- package/dist/components/ps-document-scanner-sheet.js +64 -86
- package/dist/components/ps-document-scanner.d.ts +1 -1
- package/dist/components/ps-document-scanner.js +2 -3
- package/dist/components/ps-file-picker-actions.d.ts +10 -0
- package/dist/components/ps-file-picker-actions.js +21 -0
- package/dist/components/ps-file-picker.d.ts +7 -1
- package/dist/components/ps-file-picker.js +30 -6
- package/dist/components/ps-scan-button.d.ts +13 -0
- package/dist/components/ps-scan-button.js +9 -0
- package/dist/components/ps-scan-camera-view.d.ts +11 -8
- package/dist/components/ps-scan-camera-view.js +14 -16
- package/dist/components/ps-scan-crop-editor.d.ts +4 -4
- package/dist/components/ps-scan-crop-editor.js +24 -8
- package/dist/components/ps-scan-denied-steps.d.ts +6 -0
- package/dist/components/ps-scan-denied-steps.js +33 -0
- package/dist/components/ps-scan-icon-button.d.ts +4 -3
- package/dist/components/ps-scan-icon-button.js +3 -1
- package/dist/components/ps-scan-illustration.d.ts +1 -0
- package/dist/components/ps-scan-illustration.js +6 -0
- package/dist/components/ps-scan-loupe.d.ts +10 -0
- package/dist/components/ps-scan-loupe.js +31 -0
- package/dist/components/ps-scan-permission-view.d.ts +10 -0
- package/dist/components/ps-scan-permission-view.js +48 -0
- package/dist/components/ps-scan-photo-button.d.ts +7 -0
- package/dist/components/ps-scan-photo-button.js +20 -0
- package/dist/components/ps-scan-preview.d.ts +12 -0
- package/dist/components/ps-scan-preview.js +10 -0
- package/dist/components/ps-scan-shutter.d.ts +6 -0
- package/dist/components/ps-scan-shutter.js +6 -0
- package/dist/components/ps-scan-viewfinder-overlay.d.ts +8 -0
- package/dist/components/ps-scan-viewfinder-overlay.js +28 -0
- package/dist/components/ps-upload-row.js +1 -1
- package/dist/constants/ps-document-scanner-labels.d.ts +39 -38
- package/dist/constants/ps-document-scanner-labels.js +39 -38
- package/dist/constants/ps-file-picker-labels.d.ts +5 -3
- package/dist/constants/ps-file-picker-labels.js +5 -3
- package/dist/constants/ps-scan-camera-status.d.ts +4 -0
- package/dist/constants/ps-scan-camera-status.js +4 -0
- package/dist/constants/ps-scan-chrome-classes.d.ts +10 -0
- package/dist/constants/ps-scan-chrome-classes.js +13 -0
- package/dist/constants/ps-scan-config.d.ts +34 -24
- package/dist/constants/ps-scan-config.js +34 -24
- package/dist/constants/ps-scan-platform.d.ts +6 -0
- package/dist/constants/ps-scan-platform.js +8 -0
- package/dist/constants/ps-scan-step.d.ts +1 -1
- package/dist/constants/ps-scan-step.js +1 -1
- package/dist/esm/components/ps-document-scanner-sheet.js +67 -89
- package/dist/esm/components/ps-document-scanner.js +2 -3
- package/dist/esm/components/ps-file-picker-actions.js +17 -0
- package/dist/esm/components/ps-file-picker.js +31 -7
- package/dist/esm/components/ps-scan-button.js +5 -0
- package/dist/esm/components/ps-scan-camera-view.js +17 -19
- package/dist/esm/components/ps-scan-crop-editor.js +26 -10
- package/dist/esm/components/ps-scan-denied-steps.js +29 -0
- package/dist/esm/components/ps-scan-icon-button.js +3 -1
- package/dist/esm/components/ps-scan-illustration.js +2 -0
- package/dist/esm/components/ps-scan-loupe.js +27 -0
- package/dist/esm/components/ps-scan-permission-view.js +44 -0
- package/dist/esm/components/ps-scan-photo-button.js +16 -0
- package/dist/esm/components/ps-scan-preview.js +6 -0
- package/dist/esm/components/ps-scan-shutter.js +2 -0
- package/dist/esm/components/ps-scan-viewfinder-overlay.js +24 -0
- package/dist/esm/components/ps-upload-row.js +1 -1
- package/dist/esm/constants/ps-document-scanner-labels.js +39 -38
- package/dist/esm/constants/ps-file-picker-labels.js +5 -3
- package/dist/esm/constants/ps-scan-camera-status.js +4 -0
- package/dist/esm/constants/ps-scan-chrome-classes.js +10 -0
- package/dist/esm/constants/ps-scan-config.js +34 -24
- package/dist/esm/constants/ps-scan-platform.js +5 -0
- package/dist/esm/constants/ps-scan-step.js +1 -1
- package/dist/esm/hooks/use-ps-scan-camera.js +52 -15
- package/dist/esm/hooks/use-ps-scan-live-detection.js +41 -0
- package/dist/esm/hooks/use-ps-scan-photo.js +42 -0
- package/dist/esm/index.js +1 -2
- package/dist/esm/models/ps-scan-region.js +1 -0
- package/dist/esm/models/ps-scan-result.js +1 -0
- package/dist/esm/models/ps-scan-stability.js +1 -0
- package/dist/esm/services/ps-scan-camera-service.js +52 -7
- package/dist/esm/services/ps-scan-canny-service.js +93 -0
- package/dist/esm/services/ps-scan-canvas-service.js +13 -1
- package/dist/esm/services/ps-scan-edge-service.js +73 -137
- package/dist/esm/services/ps-scan-file-name-service.js +2 -11
- package/dist/esm/services/ps-scan-geometry-service.js +56 -0
- package/dist/esm/services/ps-scan-hull-service.js +0 -39
- package/dist/esm/services/ps-scan-image-filter-service.js +0 -21
- package/dist/esm/services/ps-scan-morphology-service.js +44 -0
- package/dist/esm/services/ps-scan-pipeline-service.js +9 -19
- package/dist/esm/services/ps-scan-platform-service.js +15 -0
- package/dist/esm/services/ps-scan-polygon-service.js +75 -0
- package/dist/esm/services/ps-scan-region-service.js +52 -0
- package/dist/esm/services/ps-scan-stability-service.js +28 -0
- package/dist/esm/services/ps-scan-warp-service.js +8 -2
- package/dist/esm/services/ps-scan-yield-service.js +5 -0
- package/dist/hooks/use-ps-scan-camera.d.ts +3 -1
- package/dist/hooks/use-ps-scan-camera.js +52 -15
- package/dist/hooks/use-ps-scan-live-detection.d.ts +3 -0
- package/dist/hooks/use-ps-scan-live-detection.js +45 -0
- package/dist/hooks/use-ps-scan-photo.d.ts +9 -0
- package/dist/hooks/use-ps-scan-photo.js +46 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/models/ps-document-scanner-props.d.ts +0 -3
- package/dist/models/ps-document-scanner-sheet-props.d.ts +0 -3
- package/dist/models/ps-file-picker-scan.d.ts +4 -0
- package/dist/models/ps-scan-gradient.d.ts +4 -0
- package/dist/models/ps-scan-live-detection.d.ts +4 -0
- package/dist/models/ps-scan-located.d.ts +5 -0
- package/dist/models/ps-scan-photo.d.ts +9 -0
- package/dist/models/ps-scan-region.d.ts +5 -0
- package/dist/models/ps-scan-region.js +2 -0
- package/dist/models/ps-scan-result.d.ts +6 -0
- package/dist/models/ps-scan-result.js +2 -0
- package/dist/models/ps-scan-stability.d.ts +5 -0
- package/dist/models/ps-scan-stability.js +2 -0
- package/dist/services/ps-scan-camera-service.d.ts +4 -0
- package/dist/services/ps-scan-camera-service.js +52 -7
- package/dist/services/ps-scan-canny-service.d.ts +7 -0
- package/dist/services/ps-scan-canny-service.js +97 -0
- package/dist/services/ps-scan-canvas-service.d.ts +1 -0
- package/dist/services/ps-scan-canvas-service.js +13 -1
- package/dist/services/ps-scan-edge-service.d.ts +5 -5
- package/dist/services/ps-scan-edge-service.js +73 -137
- package/dist/services/ps-scan-file-name-service.d.ts +1 -3
- package/dist/services/ps-scan-file-name-service.js +2 -11
- package/dist/services/ps-scan-geometry-service.d.ts +4 -0
- package/dist/services/ps-scan-geometry-service.js +56 -0
- package/dist/services/ps-scan-hull-service.d.ts +0 -2
- package/dist/services/ps-scan-hull-service.js +0 -39
- package/dist/services/ps-scan-image-filter-service.d.ts +0 -1
- package/dist/services/ps-scan-image-filter-service.js +0 -21
- package/dist/services/ps-scan-morphology-service.d.ts +7 -0
- package/dist/services/ps-scan-morphology-service.js +48 -0
- package/dist/services/ps-scan-pipeline-service.d.ts +2 -5
- package/dist/services/ps-scan-pipeline-service.js +9 -19
- package/dist/services/ps-scan-platform-service.d.ts +4 -0
- package/dist/services/ps-scan-platform-service.js +19 -0
- package/dist/services/ps-scan-polygon-service.d.ts +8 -0
- package/dist/services/ps-scan-polygon-service.js +79 -0
- package/dist/services/ps-scan-region-service.d.ts +4 -0
- package/dist/services/ps-scan-region-service.js +56 -0
- package/dist/services/ps-scan-stability-service.d.ts +7 -0
- package/dist/services/ps-scan-stability-service.js +32 -0
- package/dist/services/ps-scan-warp-service.d.ts +1 -1
- package/dist/services/ps-scan-warp-service.js +8 -2
- package/dist/services/ps-scan-yield-service.d.ts +3 -0
- package/dist/services/ps-scan-yield-service.js +9 -0
- package/package.json +3 -3
- package/dist/components/ps-scan-page-list.d.ts +0 -12
- package/dist/components/ps-scan-page-list.js +0 -23
- package/dist/components/ps-scan-review.d.ts +0 -23
- package/dist/components/ps-scan-review.js +0 -20
- package/dist/constants/ps-scan-filter.d.ts +0 -7
- package/dist/constants/ps-scan-filter.js +0 -9
- package/dist/constants/ps-scan-output-format.d.ts +0 -5
- package/dist/constants/ps-scan-output-format.js +0 -7
- package/dist/esm/components/ps-scan-page-list.js +0 -19
- package/dist/esm/components/ps-scan-review.js +0 -16
- package/dist/esm/constants/ps-scan-filter.js +0 -6
- package/dist/esm/constants/ps-scan-output-format.js +0 -4
- package/dist/esm/hooks/use-ps-scan-pages.js +0 -62
- package/dist/esm/hooks/use-ps-scan-previews.js +0 -57
- package/dist/esm/services/ps-scan-enhance-service.js +0 -97
- package/dist/esm/services/ps-scan-order-service.js +0 -13
- package/dist/esm/services/ps-scan-output-service.js +0 -24
- package/dist/esm/services/ps-scan-pdf-service.js +0 -56
- package/dist/hooks/use-ps-scan-pages.d.ts +0 -12
- package/dist/hooks/use-ps-scan-pages.js +0 -66
- package/dist/hooks/use-ps-scan-previews.d.ts +0 -2
- package/dist/hooks/use-ps-scan-previews.js +0 -61
- package/dist/models/ps-scan-added-page.d.ts +0 -5
- package/dist/models/ps-scan-levels.d.ts +0 -4
- package/dist/models/ps-scan-output-options.d.ts +0 -7
- package/dist/models/ps-scan-page.d.ts +0 -12
- package/dist/models/ps-scan-pdf-page.d.ts +0 -5
- package/dist/services/ps-scan-enhance-service.d.ts +0 -9
- package/dist/services/ps-scan-enhance-service.js +0 -101
- package/dist/services/ps-scan-order-service.d.ts +0 -4
- package/dist/services/ps-scan-order-service.js +0 -17
- package/dist/services/ps-scan-output-service.d.ts +0 -5
- package/dist/services/ps-scan-output-service.js +0 -28
- package/dist/services/ps-scan-pdf-service.d.ts +0 -5
- package/dist/services/ps-scan-pdf-service.js +0 -60
- /package/dist/esm/models/{ps-scan-added-page.js → ps-file-picker-scan.js} +0 -0
- /package/dist/esm/models/{ps-scan-levels.js → ps-scan-gradient.js} +0 -0
- /package/dist/esm/models/{ps-scan-output-options.js → ps-scan-live-detection.js} +0 -0
- /package/dist/esm/models/{ps-scan-page.js → ps-scan-located.js} +0 -0
- /package/dist/esm/models/{ps-scan-pdf-page.js → ps-scan-photo.js} +0 -0
- /package/dist/models/{ps-scan-added-page.js → ps-file-picker-scan.js} +0 -0
- /package/dist/models/{ps-scan-levels.js → ps-scan-gradient.js} +0 -0
- /package/dist/models/{ps-scan-output-options.js → ps-scan-live-detection.js} +0 -0
- /package/dist/models/{ps-scan-page.js → ps-scan-located.js} +0 -0
- /package/dist/models/{ps-scan-pdf-page.js → ps-scan-photo.js} +0 -0
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PsScanFilter } from '../constants/ps-scan-filter';
|
|
2
|
-
import type { PsScanRaster } from '../models/ps-scan-raster';
|
|
3
|
-
export declare class PsScanEnhanceService {
|
|
4
|
-
static apply(source: PsScanRaster, filter: PsScanFilter): PsScanRaster;
|
|
5
|
-
private static colour;
|
|
6
|
-
private static document;
|
|
7
|
-
private static greyscale;
|
|
8
|
-
private static levels;
|
|
9
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PsScanEnhanceService = void 0;
|
|
4
|
-
const ps_scan_config_1 = require("../constants/ps-scan-config");
|
|
5
|
-
const ps_scan_filter_1 = require("../constants/ps-scan-filter");
|
|
6
|
-
const ps_scan_image_filter_service_1 = require("./ps-scan-image-filter-service");
|
|
7
|
-
const ps_scan_raster_service_1 = require("./ps-scan-raster-service");
|
|
8
|
-
class PsScanEnhanceService {
|
|
9
|
-
static apply(source, filter) {
|
|
10
|
-
if (filter === ps_scan_filter_1.PsScanFilter.Original)
|
|
11
|
-
return source;
|
|
12
|
-
if (filter === ps_scan_filter_1.PsScanFilter.Colour)
|
|
13
|
-
return PsScanEnhanceService.colour(source);
|
|
14
|
-
if (filter === ps_scan_filter_1.PsScanFilter.Greyscale)
|
|
15
|
-
return PsScanEnhanceService.greyscale(source);
|
|
16
|
-
return PsScanEnhanceService.document(source);
|
|
17
|
-
}
|
|
18
|
-
static colour(source) {
|
|
19
|
-
const gray = ps_scan_image_filter_service_1.PsScanImageFilterService.grayscale(source);
|
|
20
|
-
const { black, white } = PsScanEnhanceService.levels(gray);
|
|
21
|
-
const gain = 255 / Math.max(1, white - black);
|
|
22
|
-
const target = ps_scan_raster_service_1.PsScanRasterService.create(source.width, source.height);
|
|
23
|
-
for (let at = 0; at < source.data.length; at += 4) {
|
|
24
|
-
target.data[at] = (source.data[at] - black) * gain;
|
|
25
|
-
target.data[at + 1] = (source.data[at + 1] - black) * gain;
|
|
26
|
-
target.data[at + 2] = (source.data[at + 2] - black) * gain;
|
|
27
|
-
target.data[at + 3] = 255;
|
|
28
|
-
}
|
|
29
|
-
return target;
|
|
30
|
-
}
|
|
31
|
-
static document(source) {
|
|
32
|
-
const { height, width } = source;
|
|
33
|
-
const gray = ps_scan_image_filter_service_1.PsScanImageFilterService.grayscale(source);
|
|
34
|
-
const integral = new Float64Array((width + 1) * (height + 1));
|
|
35
|
-
for (let y = 0; y < height; y += 1) {
|
|
36
|
-
let row = 0;
|
|
37
|
-
for (let x = 0; x < width; x += 1) {
|
|
38
|
-
row += gray[y * width + x];
|
|
39
|
-
integral[(y + 1) * (width + 1) + x + 1] = integral[y * (width + 1) + x + 1] + row;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const half = Math.max(ps_scan_config_1.PsScanConfig.adaptiveWindowMin, Math.floor(Math.min(width, height) / ps_scan_config_1.PsScanConfig.adaptiveWindowDivisor)) >> 1;
|
|
43
|
-
const target = ps_scan_raster_service_1.PsScanRasterService.create(width, height);
|
|
44
|
-
for (let y = 0; y < height; y += 1) {
|
|
45
|
-
const y0 = Math.max(0, y - half);
|
|
46
|
-
const y1 = Math.min(height, y + half + 1);
|
|
47
|
-
for (let x = 0; x < width; x += 1) {
|
|
48
|
-
const x0 = Math.max(0, x - half);
|
|
49
|
-
const x1 = Math.min(width, x + half + 1);
|
|
50
|
-
const sum = integral[y1 * (width + 1) + x1] -
|
|
51
|
-
integral[y0 * (width + 1) + x1] -
|
|
52
|
-
integral[y1 * (width + 1) + x0] +
|
|
53
|
-
integral[y0 * (width + 1) + x0];
|
|
54
|
-
const mean = sum / ((x1 - x0) * (y1 - y0));
|
|
55
|
-
const value = gray[y * width + x] < mean * ps_scan_config_1.PsScanConfig.adaptiveRatio ? 0 : 255;
|
|
56
|
-
const at = (y * width + x) * 4;
|
|
57
|
-
target.data[at] = value;
|
|
58
|
-
target.data[at + 1] = value;
|
|
59
|
-
target.data[at + 2] = value;
|
|
60
|
-
target.data[at + 3] = 255;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return target;
|
|
64
|
-
}
|
|
65
|
-
static greyscale(source) {
|
|
66
|
-
const gray = ps_scan_image_filter_service_1.PsScanImageFilterService.grayscale(source);
|
|
67
|
-
const { black, white } = PsScanEnhanceService.levels(gray);
|
|
68
|
-
const gain = 255 / Math.max(1, white - black);
|
|
69
|
-
const target = ps_scan_raster_service_1.PsScanRasterService.create(source.width, source.height);
|
|
70
|
-
for (let index = 0; index < gray.length; index += 1) {
|
|
71
|
-
const value = (gray[index] - black) * gain;
|
|
72
|
-
const at = index * 4;
|
|
73
|
-
target.data[at] = value;
|
|
74
|
-
target.data[at + 1] = value;
|
|
75
|
-
target.data[at + 2] = value;
|
|
76
|
-
target.data[at + 3] = 255;
|
|
77
|
-
}
|
|
78
|
-
return target;
|
|
79
|
-
}
|
|
80
|
-
static levels(gray) {
|
|
81
|
-
const bins = new Uint32Array(256);
|
|
82
|
-
gray.forEach((value) => {
|
|
83
|
-
bins[value] += 1;
|
|
84
|
-
});
|
|
85
|
-
const find = (fraction) => {
|
|
86
|
-
const target = gray.length * fraction;
|
|
87
|
-
let cumulative = 0;
|
|
88
|
-
for (let bin = 0; bin < 256; bin += 1) {
|
|
89
|
-
cumulative += bins[bin];
|
|
90
|
-
if (cumulative >= target)
|
|
91
|
-
return bin;
|
|
92
|
-
}
|
|
93
|
-
return 255;
|
|
94
|
-
};
|
|
95
|
-
return {
|
|
96
|
-
black: find(ps_scan_config_1.PsScanConfig.levelLowPercentile),
|
|
97
|
-
white: find(ps_scan_config_1.PsScanConfig.levelHighPercentile),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.PsScanEnhanceService = PsScanEnhanceService;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PsScanOrderService = void 0;
|
|
4
|
-
class PsScanOrderService {
|
|
5
|
-
static move(items, from, to) {
|
|
6
|
-
if (from === to || from < 0 || to < 0 || from >= items.length || to >= items.length)
|
|
7
|
-
return items;
|
|
8
|
-
const next = [...items];
|
|
9
|
-
const [item] = next.splice(from, 1);
|
|
10
|
-
next.splice(to, 0, item);
|
|
11
|
-
return next;
|
|
12
|
-
}
|
|
13
|
-
static step(items, index, direction) {
|
|
14
|
-
return PsScanOrderService.move(items, index, index + direction);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.PsScanOrderService = PsScanOrderService;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PsScanOutputService = void 0;
|
|
4
|
-
const ps_scan_output_format_1 = require("../constants/ps-scan-output-format");
|
|
5
|
-
const ps_scan_file_name_service_1 = require("./ps-scan-file-name-service");
|
|
6
|
-
const ps_scan_pdf_service_1 = require("./ps-scan-pdf-service");
|
|
7
|
-
const ps_scan_pipeline_service_1 = require("./ps-scan-pipeline-service");
|
|
8
|
-
class PsScanOutputService {
|
|
9
|
-
static async build(pages, options) {
|
|
10
|
-
const rendered = [];
|
|
11
|
-
for (const page of pages)
|
|
12
|
-
rendered.push(await ps_scan_pipeline_service_1.PsScanPipelineService.render(page, options.maxDimension, options.jpegQuality));
|
|
13
|
-
const type = ps_scan_file_name_service_1.PsScanFileNameService.mimeType(options.format);
|
|
14
|
-
if (options.format === ps_scan_output_format_1.PsScanOutputFormat.Jpeg)
|
|
15
|
-
return rendered.map((item, index) => new File([item.blob], ps_scan_file_name_service_1.PsScanFileNameService.build(options.fileName, options.format, index, rendered.length), { type }));
|
|
16
|
-
const jpegs = await Promise.all(rendered.map(async (item) => ({
|
|
17
|
-
height: item.height,
|
|
18
|
-
jpeg: new Uint8Array(await item.blob.arrayBuffer()),
|
|
19
|
-
width: item.width,
|
|
20
|
-
})));
|
|
21
|
-
return [
|
|
22
|
-
new File([ps_scan_pdf_service_1.PsScanPdfService.build(jpegs)], ps_scan_file_name_service_1.PsScanFileNameService.build(options.fileName, options.format, 0, 1), {
|
|
23
|
-
type,
|
|
24
|
-
}),
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.PsScanOutputService = PsScanOutputService;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PsScanPdfService = void 0;
|
|
4
|
-
const ps_scan_config_1 = require("../constants/ps-scan-config");
|
|
5
|
-
class PsScanPdfService {
|
|
6
|
-
static build(pages) {
|
|
7
|
-
const encoder = new TextEncoder();
|
|
8
|
-
const chunks = [];
|
|
9
|
-
const offsets = [];
|
|
10
|
-
let length = 0;
|
|
11
|
-
const push = (chunk) => {
|
|
12
|
-
chunks.push(chunk);
|
|
13
|
-
length += chunk.length;
|
|
14
|
-
};
|
|
15
|
-
const text = (value) => push(encoder.encode(value));
|
|
16
|
-
const begin = (id) => {
|
|
17
|
-
offsets[id] = length;
|
|
18
|
-
text(`${id} 0 obj\n`);
|
|
19
|
-
};
|
|
20
|
-
const kids = pages.map((_, index) => `${3 + index * 3} 0 R`).join(' ');
|
|
21
|
-
push(Uint8Array.from([
|
|
22
|
-
0x25, 0x50, 0x44, 0x46, 0x2d, 0x31, 0x2e, 0x34, 0x0a, 0x25, 0xe2, 0xe3, 0xcf, 0xd3, 0x0a,
|
|
23
|
-
]));
|
|
24
|
-
begin(1);
|
|
25
|
-
text('<< /Type /Catalog /Pages 2 0 R >>\nendobj\n');
|
|
26
|
-
begin(2);
|
|
27
|
-
text(`<< /Type /Pages /Kids [${kids}] /Count ${pages.length} >>\nendobj\n`);
|
|
28
|
-
pages.forEach((page, index) => {
|
|
29
|
-
const pageId = 3 + index * 3;
|
|
30
|
-
const widthPt = PsScanPdfService.points(page.width);
|
|
31
|
-
const heightPt = PsScanPdfService.points(page.height);
|
|
32
|
-
const content = `q ${widthPt} 0 0 ${heightPt} 0 0 cm /Im0 Do Q`;
|
|
33
|
-
begin(pageId);
|
|
34
|
-
text(`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${widthPt} ${heightPt}] /Resources << /XObject << /Im0 ${pageId + 2} 0 R >> >> /Contents ${pageId + 1} 0 R >>\nendobj\n`);
|
|
35
|
-
begin(pageId + 1);
|
|
36
|
-
text(`<< /Length ${content.length} >>\nstream\n${content}\nendstream\nendobj\n`);
|
|
37
|
-
begin(pageId + 2);
|
|
38
|
-
text(`<< /Type /XObject /Subtype /Image /Width ${page.width} /Height ${page.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${page.jpeg.length} >>\nstream\n`);
|
|
39
|
-
push(page.jpeg);
|
|
40
|
-
text('\nendstream\nendobj\n');
|
|
41
|
-
});
|
|
42
|
-
const count = 3 + pages.length * 3;
|
|
43
|
-
const xrefAt = length;
|
|
44
|
-
text(`xref\n0 ${count}\n0000000000 65535 f \n`);
|
|
45
|
-
for (let id = 1; id < count; id += 1)
|
|
46
|
-
text(`${String(offsets[id]).padStart(10, '0')} 00000 n \n`);
|
|
47
|
-
text(`trailer\n<< /Size ${count} /Root 1 0 R >>\nstartxref\n${xrefAt}\n%%EOF\n`);
|
|
48
|
-
const out = new Uint8Array(length);
|
|
49
|
-
let at = 0;
|
|
50
|
-
chunks.forEach((chunk) => {
|
|
51
|
-
out.set(chunk, at);
|
|
52
|
-
at += chunk.length;
|
|
53
|
-
});
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
static points(pixels) {
|
|
57
|
-
return Math.round((pixels * ps_scan_config_1.PsScanConfig.pdfPointsPerInch * 100) / ps_scan_config_1.PsScanConfig.pdfDpi) / 100;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.PsScanPdfService = PsScanPdfService;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|