pdf-visual-compare 3.1.0 → 3.2.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/out/comparePdf.js +15 -12
- package/out/const.js +5 -2
- package/out/index.js +5 -1
- package/out/types/ComparePdfOptions.js +2 -1
- package/out/types/ExcludedPageArea.js +2 -1
- package/package.json +3 -3
package/out/comparePdf.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.comparePdf = comparePdf;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const pdf_to_png_converter_1 = require("pdf-to-png-converter");
|
|
7
|
+
const png_visual_compare_1 = require("png-visual-compare");
|
|
8
|
+
const const_js_1 = require("./const.js");
|
|
6
9
|
/**
|
|
7
10
|
* Compares two PDF files or buffers and returns a boolean indicating whether they are similar.
|
|
8
11
|
*
|
|
@@ -12,7 +15,7 @@ import { DEFAULT_DIFFS_FOLDER } from './const.js';
|
|
|
12
15
|
* @returns A promise that resolves to a boolean indicating whether the PDFs are similar.
|
|
13
16
|
* @throws Will throw an error if the compare threshold is less than 0.
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
async function comparePdf(actualPdf, expectedPdf, opts = {}) {
|
|
16
19
|
// Validate input file types
|
|
17
20
|
validateInputFileType(actualPdf);
|
|
18
21
|
validateInputFileType(expectedPdf);
|
|
@@ -24,7 +27,7 @@ export async function comparePdf(actualPdf, expectedPdf, opts = {}) {
|
|
|
24
27
|
if (!pdfToPngConvertOpts.outputFileMaskFunc) {
|
|
25
28
|
pdfToPngConvertOpts.outputFileMaskFunc = (pageNumber) => `comparePdf_${pageNumber}.png`;
|
|
26
29
|
}
|
|
27
|
-
const diffsOutputFolder = opts?.diffsOutputFolder ?? DEFAULT_DIFFS_FOLDER;
|
|
30
|
+
const diffsOutputFolder = opts?.diffsOutputFolder ?? const_js_1.DEFAULT_DIFFS_FOLDER;
|
|
28
31
|
const compareThreshold = opts?.compareThreshold ?? 0;
|
|
29
32
|
const excludedAreas = opts?.excludedAreas ?? [];
|
|
30
33
|
if (compareThreshold < 0) {
|
|
@@ -32,8 +35,8 @@ export async function comparePdf(actualPdf, expectedPdf, opts = {}) {
|
|
|
32
35
|
}
|
|
33
36
|
// Convert PDFs to PNGs
|
|
34
37
|
let [actualPdfPngPages, expectedPdfPngPages] = await Promise.all([
|
|
35
|
-
pdfToPng(actualPdf, pdfToPngConvertOpts),
|
|
36
|
-
pdfToPng(expectedPdf, pdfToPngConvertOpts),
|
|
38
|
+
(0, pdf_to_png_converter_1.pdfToPng)(actualPdf, pdfToPngConvertOpts),
|
|
39
|
+
(0, pdf_to_png_converter_1.pdfToPng)(expectedPdf, pdfToPngConvertOpts),
|
|
37
40
|
]);
|
|
38
41
|
// Ensure actualPdfPngPages is always the longer array to avoid index out of bounds errors
|
|
39
42
|
if (actualPdfPngPages.length < expectedPdfPngPages.length) {
|
|
@@ -46,9 +49,9 @@ export async function comparePdf(actualPdf, expectedPdf, opts = {}) {
|
|
|
46
49
|
...excludedAreas[index],
|
|
47
50
|
throwErrorOnInvalidInputData: false,
|
|
48
51
|
};
|
|
49
|
-
comparePngOpts.diffFilePath = resolve(diffsOutputFolder, `diff_${pngPage.name}`);
|
|
52
|
+
comparePngOpts.diffFilePath = (0, node_path_1.resolve)(diffsOutputFolder, `diff_${pngPage.name}`);
|
|
50
53
|
const pngPageOutputToCompareWith = expectedPdfPngPages.find((p) => p.name === pngPage.name);
|
|
51
|
-
const pageCompareResult = comparePng(pngPage.content, pngPageOutputToCompareWith?.content ?? '', comparePngOpts);
|
|
54
|
+
const pageCompareResult = (0, png_visual_compare_1.comparePng)(pngPage.content, pngPageOutputToCompareWith?.content ?? '', comparePngOpts);
|
|
52
55
|
if (pageCompareResult > compareThreshold) {
|
|
53
56
|
documentCompareResult = false;
|
|
54
57
|
}
|
|
@@ -71,7 +74,7 @@ function validateInputFileType(inputFile) {
|
|
|
71
74
|
return;
|
|
72
75
|
}
|
|
73
76
|
if (typeof inputFile === 'string') {
|
|
74
|
-
if (existsSync(inputFile)) {
|
|
77
|
+
if ((0, node_fs_1.existsSync)(inputFile)) {
|
|
75
78
|
return;
|
|
76
79
|
}
|
|
77
80
|
else {
|
package/out/const.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_DIFFS_FOLDER = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
exports.DEFAULT_DIFFS_FOLDER = (0, node_path_1.resolve)(`./comparePdfOutput`);
|
package/out/index.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.comparePdf = void 0;
|
|
4
|
+
var comparePdf_js_1 = require("./comparePdf.js");
|
|
5
|
+
Object.defineProperty(exports, "comparePdf", { enumerable: true, get: function () { return comparePdf_js_1.comparePdf; } });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-visual-compare",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Visual regression testing library for PDFs in Js/Ts without binary and OS dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pdf",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"test:docker": "npm run docker:build && npm run docker:run"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"pdf-to-png-converter": "~3.
|
|
46
|
-
"png-visual-compare": "~3.
|
|
45
|
+
"pdf-to-png-converter": "~3.10.0",
|
|
46
|
+
"png-visual-compare": "~3.2.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^24.5.2",
|