pdf-visual-compare 1.1.0 → 1.2.1

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 CHANGED
@@ -1,4 +1,45 @@
1
1
  # pdf-visual-compare
2
- Visual regression testing library for PDFs in Js/Ts
2
+
3
+ Visual regression testing library for PDFs in Js/Ts without binary and OS dependencies.
3
4
 
4
5
  [![Tests on push](https://github.com/dichovsky/pdf-visual-compare/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/dichovsky/pdf-visual-compare/actions/workflows/test.yml)
6
+
7
+ ## Getting started
8
+
9
+ Installation:
10
+
11
+ ```sh
12
+ npm install -D pdf-visual-compare
13
+ ```
14
+
15
+ ## Example
16
+
17
+ ```javascript
18
+ const result: boolean = await comparePdf('./pdf1.pdf', './pdf2.pdf');
19
+
20
+ // If you want to configure comparing process, use the following props
21
+
22
+ const result: boolean = await comparePdf('./pdf1.pdf', './pdf2.pdf', {
23
+ diffsOutputFolder?: string; // Folder to write output PNG files with differences
24
+ pdfToPngConvertOptions?: {
25
+ viewportScale: 2.0, // The desired scale of PNG viewport. Default value is 1.0.
26
+ disableFontFace: false, //When `false`, fonts will be rendered using a built-in font renderer that constructs the glyphs with primitive path commands. Default value is true.
27
+ useSystemFonts: false, // When `true`, fonts that aren't embedded in the PDF document will fallback to a system font. Default value is false.
28
+ pdfFilePassword: 'pa$$word', // Password for encrypted PDF.
29
+ outputFolder: 'output/folder', // Folder to write output PNG files. If not specified, PNG output will be available only as a Buffer content, without saving to a file.
30
+ outputFileMask: 'buffer', // Output filename mask. Default value is 'buffer'.
31
+ pagesToProcess: [1, 3, 11], // Subset of pages to convert (first page = 1), other pages will be skipped if specified.
32
+ strictPagesToProcess: false // When `true`, will throw an error if specified page number in pagesToProcess is invalid, otherwise will skip invalid page. Default value is false.
33
+ verbosityLevel: 0 // Verbosity level. ERRORS: 0, WARNINGS: 1, INFOS: 5. Default value is 0.
34
+ };
35
+ excludedAreas?: ExcludedPageArea[]; // Areas list to exclude from comparing for each PDF page. Empty array by default.
36
+ compareThreshold?: number; // Comparing threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. 0.1 by default.
37
+ });
38
+
39
+ ```
40
+
41
+ ## Buy Me A Coffee
42
+
43
+ In case you want support my work
44
+
45
+ [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://buymeacoffee.com/dichovsky)
@@ -1,2 +1,3 @@
1
1
  import { ComparePdfOptions } from './types';
2
2
  export default function comparePdf(actualPdfFilePathOrBuffer: string | ArrayBufferLike, expectedPdfFilePathOrBuffer: string | ArrayBufferLike, opts?: ComparePdfOptions): Promise<boolean>;
3
+ //# sourceMappingURL=compare.pdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.pdf.d.ts","sourceRoot":"","sources":["../src/compare.pdf.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAqC,MAAM,SAAS,CAAC;AAE/E,wBAA8B,UAAU,CACtC,yBAAyB,EAAE,MAAM,GAAG,eAAe,EACnD,2BAA2B,EAAE,MAAM,GAAG,eAAe,EACrD,IAAI,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,OAAO,CAAC,CAqDlB"}
@@ -14,10 +14,13 @@ async function comparePdf(actualPdfFilePathOrBuffer, expectedPdfFilePathOrBuffer
14
14
  if (!Buffer.isBuffer(expectedPdfFilePathOrBuffer) && !(0, fs_1.existsSync)(expectedPdfFilePathOrBuffer)) {
15
15
  throw Error('Expected PDF file not found.');
16
16
  }
17
- const pdfToPngConvertOpts = opts?.pdfToPngConvertOptions ?? {
18
- viewportScale: 2.0,
19
- outputFileMask: 'comparePdf',
20
- };
17
+ const pdfToPngConvertOpts = { ...opts?.pdfToPngConvertOptions };
18
+ if (!pdfToPngConvertOpts.viewportScale) {
19
+ pdfToPngConvertOpts.viewportScale = 2.0;
20
+ }
21
+ if (!pdfToPngConvertOpts.outputFileMask) {
22
+ pdfToPngConvertOpts.outputFileMask = 'comparePdf';
23
+ }
21
24
  const diffsOutputFolder = opts?.diffsOutputFolder
22
25
  ? opts.diffsOutputFolder
23
26
  : (0, path_1.resolve)(`./comparePdfOutput`);
@@ -37,17 +40,17 @@ async function comparePdf(actualPdfFilePathOrBuffer, expectedPdfFilePathOrBuffer
37
40
  if (actualPdfPngPages.length !== expectedPdfPngPages.length) {
38
41
  return false;
39
42
  }
40
- let overallCompareResult = true;
43
+ let documentCompareResult = true;
41
44
  actualPdfPngPages.forEach((actualPdfPngPage, index) => {
42
45
  const comparePngOpts = { ...opts?.pdfToPngConvertOptions, ...excludedAreas[index] };
43
46
  comparePngOpts.diffFilePath = (0, path_1.resolve)(diffsOutputFolder, `diff_${actualPdfPngPage.name}`);
44
- const expectedPdfPngPage = expectedPdfPngPages.find((expectedPdfPngPage) => expectedPdfPngPage.name === actualPdfPngPage.name);
45
- const compareResult = (0, png_visual_compare_1.default)(actualPdfPngPage.content, expectedPdfPngPage.content, comparePngOpts);
46
- if (compareResult > compareThreshold) {
47
- overallCompareResult = false;
47
+ const expectedPngPageOutput = expectedPdfPngPages.find((p) => p.name === actualPdfPngPage.name);
48
+ const pageCompareResult = (0, png_visual_compare_1.default)(actualPdfPngPage.content, expectedPngPageOutput.content, comparePngOpts);
49
+ if (pageCompareResult > compareThreshold) {
50
+ documentCompareResult = false;
48
51
  }
49
52
  });
50
- return overallCompareResult;
53
+ return documentCompareResult;
51
54
  }
52
55
  exports.default = comparePdf;
53
56
  //# sourceMappingURL=compare.pdf.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compare.pdf.js","sourceRoot":"","sources":["../src/compare.pdf.ts"],"names":[],"mappings":";;;;;AAAA,2BAAgC;AAChC,+BAA+B;AAC/B,+DAA+D;AAC/D,4EAAmE;AAGpD,KAAK,UAAU,UAAU,CACtC,yBAAmD,EACnD,2BAAqD,EACrD,IAAwB;IAExB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CA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EAAE,QAAQ,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QAE1F,MAAM,qBAAqB,GAAkB,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAAC,IAAI,CAAkB,CAAC;QAChI,MAAM,iBAAiB,GAAW,IAAA,4BAAU,EAAC,gBAAgB,CAAC,OAAO,EAAE,qBAAqB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAEtH,IAAI,iBAAiB,GAAG,gBAAgB,EAAE;YACxC,qBAAqB,GAAG,KAAK,CAAC;SAC/B;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAzDD,6BAyDC"}
package/out/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import comparePdf from './compare.pdf';
2
2
  export default comparePdf;
3
3
  export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,eAAe,UAAU,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -5,3 +5,4 @@ export declare type ComparePdfOptions = {
5
5
  excludedAreas?: ExcludedPageArea[];
6
6
  compareThreshold?: number;
7
7
  };
8
+ //# sourceMappingURL=compare.options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.options.d.ts","sourceRoot":"","sources":["../../src/types/compare.options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,GAAG,CAAC;AAEtD,oBAAY,iBAAiB,GAAG;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sBAAsB,CAAC,EAAE,eAAe,CAAC;IACzC,aAAa,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACnC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC"}
@@ -6,3 +6,4 @@ export declare type ExcludedPageArea = {
6
6
  diffFilePath?: string;
7
7
  matchingThreshold?: number;
8
8
  };
9
+ //# sourceMappingURL=excluded.page.area.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excluded.page.area.d.ts","sourceRoot":"","sources":["../../src/types/excluded.page.area.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC;AAEhC,oBAAY,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC;IACvB,iBAAiB,CAAC,EAAE,KAAK,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC"}
@@ -2,3 +2,4 @@ export { PdfToPngOptions } from 'pdf-to-png-converter';
2
2
  export { Area, Color } from 'png-visual-compare';
3
3
  export { ComparePdfOptions } from '../types/compare.options';
4
4
  export { ExcludedPageArea } from './excluded.page.area';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-visual-compare",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Visual regression testing library for PDFs in Js/Ts without binary and OS dependencies.",
5
5
  "keywords": [
6
6
  "pdf",
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "scripts": {
27
27
  "build": "npm run clean && npm run tsc",
28
- "clean": "rimraf ./out ./coverage ./test-results",
28
+ "clean": "rimraf ./out ./coverage ./test-results ./comparePdfOutput",
29
29
  "docker:build": "docker build --compress -t test-pdf-visual-compare .",
30
30
  "predocker:run": "npm run clean",
31
31
  "docker:run": "docker run --rm -it -v ./test-results:/usr/pkg/test-results test-pdf-visual-compare",
@@ -33,24 +33,24 @@
33
33
  "license-checker": "npx license-checker --production --onlyAllow 'MIT; MIT OR X11; BSD; ISC; Apache-2.0; Unlicense'",
34
34
  "lint": "eslint .",
35
35
  "lint:fix": "npm run lint -- --fix",
36
- "pretest": "npm run clean",
36
+ "pretest": "npm run build",
37
37
  "test": "jest",
38
38
  "test:docker": "npm run docker:build && npm run docker:run",
39
39
  "tsc": "tsc --pretty"
40
40
  },
41
41
  "dependencies": {
42
- "pdf-to-png-converter": "2.0.0",
43
- "png-visual-compare": "0.4.12"
42
+ "pdf-to-png-converter": "2.3.0",
43
+ "png-visual-compare": "0.4.14"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/jest": "27.5.1",
47
- "@types/node": "17.0.34",
48
- "@typescript-eslint/eslint-plugin": "5.25.0",
49
- "@typescript-eslint/parser": "5.25.0",
50
- "eslint": "8.15.0",
51
- "jest": "28.1.0",
52
- "ts-jest": "28.0.2",
53
- "ts-node": "10.7.0",
54
- "typescript": "4.6.4"
46
+ "@types/jest": "28.1.6",
47
+ "@types/node": "18.6.3",
48
+ "@typescript-eslint/eslint-plugin": "5.32.0",
49
+ "@typescript-eslint/parser": "5.32.0",
50
+ "eslint": "8.21.0",
51
+ "jest": "28.1.3",
52
+ "ts-jest": "28.0.7",
53
+ "ts-node": "10.9.1",
54
+ "typescript": "4.7.4"
55
55
  }
56
56
  }