compare-pdf-ts 0.0.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/LICENSE +21 -0
- package/README.md +78 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DirtCheapDeeds
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# compare-pdf-ts
|
|
2
|
+
|
|
3
|
+
Node package that compares PDF files via pixel comparison. Largely inspired by the [pdf-compare](https://github.com/marcdacz/compare-pdf) package, however this package differs in that it does everything in-memory without the need for reading/writing files.
|
|
4
|
+
|
|
5
|
+
## Dependencies
|
|
6
|
+
|
|
7
|
+
This package requires the following dependencies in your project:
|
|
8
|
+
|
|
9
|
+
- [pdf-dist](https://github.com/mozilla/pdf.js)
|
|
10
|
+
- [@napi-rs/canvas](https://github.com/Brooooooklyn/canvas)
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
Install this package and required dependencies:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install compare-pdf-ts
|
|
18
|
+
npm install pdf-dist
|
|
19
|
+
npm install @napi-rs/canvas
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { comparePdfs } from "compare-pdf-ts";
|
|
26
|
+
|
|
27
|
+
const pdf1 = readFileSync("./example1.pdf");
|
|
28
|
+
const pdf2 = readFileSync("./example2.pdf");
|
|
29
|
+
|
|
30
|
+
const { equal, diffs } = await comparePdfs(pdf1, pdf2);
|
|
31
|
+
|
|
32
|
+
if (!equal) {
|
|
33
|
+
diffs.forEach(({ diffPng, pageNumber }) => {
|
|
34
|
+
writeFileSync(`page-${pageNumber}-diff.png`, diffPng);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Comparison Options
|
|
40
|
+
|
|
41
|
+
You can optionally pass some options when calling the `comparePdfs` function to tailor its behavior:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const { equal, diffs } = await comparePdfs(pdf1, pdf2, {
|
|
45
|
+
pngScale: 1.5
|
|
46
|
+
diffThreshold: 0.2
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The options type:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
type ComparePdfsOptions = {
|
|
54
|
+
pngScale: number;
|
|
55
|
+
considerAntiAliasing: boolean;
|
|
56
|
+
includeDiffMask: boolean;
|
|
57
|
+
diffThreshold: number;
|
|
58
|
+
diffAlpha: number;
|
|
59
|
+
diffAntiAliasingColor: [number, number, number];
|
|
60
|
+
diffColor: [number, number, number];
|
|
61
|
+
diffColorAlt: [number, number, number];
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The default option values:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const DEFAULT_COMPARE_PDFS_OPTIONS: ComparePdfsOptions = {
|
|
69
|
+
pngScale: 1.0,
|
|
70
|
+
considerAntiAliasing: false,
|
|
71
|
+
includeDiffMask: false,
|
|
72
|
+
diffThreshold: 0.1,
|
|
73
|
+
diffAlpha: 0.1,
|
|
74
|
+
diffAntiAliasingColor: [255, 255, 0],
|
|
75
|
+
diffColor: [255, 0, 0],
|
|
76
|
+
diffColorAlt: [255, 0, 0],
|
|
77
|
+
};
|
|
78
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "compare-pdf-ts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "DirtCheapDeeds",
|
|
5
|
+
"repository": "https://github.com/DirtCheapDeeds/compare-pdf-ts",
|
|
6
|
+
"description": "In-memory PDF comparison tool designed for Node.js environments.",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"pdf",
|
|
10
|
+
"compare pdf"
|
|
11
|
+
],
|
|
12
|
+
"files": [
|
|
13
|
+
"package.json",
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/cjs/index.cjs",
|
|
17
|
+
"module": "./dist/esm/index.mjs",
|
|
18
|
+
"types": "./dist/types/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/types/index.d.ts",
|
|
22
|
+
"import": "./dist/esm/index.mjs",
|
|
23
|
+
"require": "./dist/cjs/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"format": "prettier --write .",
|
|
28
|
+
"format:check": "prettier --check .",
|
|
29
|
+
"lint": "eslint src",
|
|
30
|
+
"lint:fix": "eslint src --fix",
|
|
31
|
+
"test": "vitest --run",
|
|
32
|
+
"build:types": "tsc",
|
|
33
|
+
"bundle:cjs": "tsx build/bundle-cjs.ts",
|
|
34
|
+
"bundle:esm": "tsx build/bundle-esm.ts",
|
|
35
|
+
"build": "npm run build:types && npm run bundle:cjs && npm run bundle:esm",
|
|
36
|
+
"quality-check": "npm install && npm run format && npm run lint:fix && npm run test && npm run build:types"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@swc/core": "^1.15.8",
|
|
40
|
+
"@types/pixelmatch": "^5.2.6",
|
|
41
|
+
"@types/pngjs": "^6.0.5",
|
|
42
|
+
"esbuild": "^0.27.2",
|
|
43
|
+
"eslint": "^9.39.2",
|
|
44
|
+
"eslint-config-prettier": "^10.1.8",
|
|
45
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
46
|
+
"eslint-plugin-functional": "^9.0.2",
|
|
47
|
+
"eslint-plugin-import": "^2.32.0",
|
|
48
|
+
"jiti": "^2.6.1",
|
|
49
|
+
"prettier": "^3.7.4",
|
|
50
|
+
"ts-node": "^10.9.2",
|
|
51
|
+
"tsx": "^4.21.0",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"typescript-eslint": "^8.52.0",
|
|
54
|
+
"ts-xor": "^1.3.0",
|
|
55
|
+
"vitest": "^4.0.16"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@napi-rs/canvas": "^0.1.88",
|
|
59
|
+
"pdfjs-dist": "^5.4.530",
|
|
60
|
+
"pixelmatch": "^7.1.0",
|
|
61
|
+
"pngjs": "^7.0.0"
|
|
62
|
+
}
|
|
63
|
+
}
|