@jackgreen2018/pdf-engine 1.0.103 → 1.0.105
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 +6 -6
- package/dist/cli.d.ts +15 -2
- package/dist/cli.js +15 -15
- package/dist/index.d.ts +6 -6
- package/dist/index.js +0 -1
- package/package.json +2 -2
- package/pkg/README.md +6 -6
- package/pkg/package.json +2 -2
- package/pkg/pdf_engine_bg.wasm +0 -0
- package/LICENSE +0 -21
- package/dist/cli.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/pkg/LICENSE +0 -21
- package/src/cli.ts +0 -66
- package/src/index.ts +0 -62
package/README.md
CHANGED
|
@@ -114,14 +114,14 @@ npm run benchmark
|
|
|
114
114
|
|
|
115
115
|
| Operation | pdf-engine (ms) | pdf-lib (ms) |
|
|
116
116
|
|-----------|-----------------|--------------|
|
|
117
|
-
| Page Count | 0.
|
|
118
|
-
| Text Extraction | 0.
|
|
119
|
-
| Merge (2 files) | 0.
|
|
120
|
-
| Split (pages [0,1]) | 0.
|
|
117
|
+
| Page Count | 0.60 | 1.42 |
|
|
118
|
+
| Text Extraction | 0.22 | — |
|
|
119
|
+
| Merge (2 files) | 0.91 | 3.95 |
|
|
120
|
+
| Split (pages [0,1]) | 0.27 | 1.82 |
|
|
121
121
|
|
|
122
|
-
*extractText correctness: PASS — gated via `tests/fixtures/text-fixture.pdf` (FlateDecode-compressed, real-world content stream)
|
|
122
|
+
*extractText correctness: PASS — gated via `tests/fixtures/text-fixture.pdf` (FlateDecode-compressed, real-world content stream).*
|
|
123
123
|
|
|
124
|
-
*Run 2026-08-03
|
|
124
|
+
*Run 2026-08-03; raw JSON at benchmark-results.json.*
|
|
125
125
|
|
|
126
126
|
## Commercial license & support
|
|
127
127
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import pdfEngine from './index.js';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
const USAGE = `pdf-engine — Rust/WASM PDF processing (v${require('../package.json').version})
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
pdf-engine <command> [args]
|
|
9
|
+
|
|
10
|
+
Commands:
|
|
11
|
+
page-count <file> Print the page count of a PDF
|
|
12
|
+
extract-text <file> Extract text from a PDF
|
|
13
|
+
merge <file1> <file2> ... Merge PDFs into a single output
|
|
14
|
+
split <file> <page1> ... Split a PDF by 0-based page indices
|
|
15
|
+
help Print this message
|
|
16
|
+
`;
|
package/dist/cli.js
CHANGED
|
@@ -30,31 +30,31 @@ async function main() {
|
|
|
30
30
|
return 0;
|
|
31
31
|
}
|
|
32
32
|
case 'extract-text': {
|
|
33
|
-
const
|
|
34
|
-
process.stdout.write(
|
|
33
|
+
const text = await pdfEngine.extractText(await read(args[0]));
|
|
34
|
+
process.stdout.write(text + '\n');
|
|
35
35
|
return 0;
|
|
36
36
|
}
|
|
37
37
|
case 'merge': {
|
|
38
|
-
const
|
|
39
|
-
await
|
|
40
|
-
|
|
38
|
+
const buffers = await Promise.all(args.map(read));
|
|
39
|
+
const merged = await pdfEngine.merge(buffers);
|
|
40
|
+
await fs.writeFile(args[args.length], merged);
|
|
41
41
|
return 0;
|
|
42
42
|
}
|
|
43
43
|
case 'split': {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const buffer = await read(args[0]);
|
|
45
|
+
const pages = args.slice(1).map(Number);
|
|
46
|
+
const parts = await pdfEngine.split(buffer, pages);
|
|
47
|
+
for (let i = 0; i < parts.length; i++) {
|
|
48
|
+
const out = `${args[0]}_page_${i}.pdf`;
|
|
49
|
+
await fs.writeFile(out, parts[i]);
|
|
50
|
+
process.stdout.write(`Wrote ${out} (${parts[i].length} bytes)\n`);
|
|
48
51
|
}
|
|
49
|
-
process.stdout.write(`wrote ${out.length} part-*.pdf files\n`);
|
|
50
52
|
return 0;
|
|
51
53
|
}
|
|
52
54
|
default:
|
|
53
|
-
process.stderr.write(`
|
|
55
|
+
process.stderr.write(`Unknown command: ${cmd}\n`);
|
|
56
|
+
process.stdout.write(USAGE);
|
|
54
57
|
return 1;
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
main().
|
|
58
|
-
process.stderr.write(String(e) + '\n');
|
|
59
|
-
process.exit(1);
|
|
60
|
-
});
|
|
60
|
+
main().catch(e => { console.error(e); process.exit(1); });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
// PDF Engine TypeScript bindings for Rust/WASM PDF processing library
|
|
2
|
+
import * as wasm from '../pkg/pdf_engine.js';
|
|
1
3
|
export declare function initialize(): Promise<void>;
|
|
2
4
|
export declare function getPageCount(buffer: Uint8Array): Promise<number>;
|
|
3
5
|
export declare function extractText(buffer: Uint8Array): Promise<string>;
|
|
4
|
-
export declare function merge(pdfBuffers:
|
|
5
|
-
export declare function split(buffer: Uint8Array, pages:
|
|
6
|
+
export declare function merge(pdfBuffers: Array<any>): Promise<Uint8Array>;
|
|
7
|
+
export declare function split(buffer: Uint8Array, pages: Array<any>): Promise<Array<any>>;
|
|
6
8
|
export declare class PdfEngineImpl {
|
|
7
|
-
constructor();
|
|
8
9
|
private initialized;
|
|
9
10
|
init(): Promise<void>;
|
|
10
11
|
getPageCount(buffer: Uint8Array): Promise<number>;
|
|
11
12
|
extractText(buffer: Uint8Array): Promise<string>;
|
|
12
|
-
merge(pdfBuffers:
|
|
13
|
-
split(buffer: Uint8Array, pages:
|
|
13
|
+
merge(pdfBuffers: Array<any>): Promise<Uint8Array>;
|
|
14
|
+
split(buffer: Uint8Array, pages: Array<any>): Promise<Array<any>>;
|
|
14
15
|
}
|
|
15
16
|
declare const pdfEngine: PdfEngineImpl;
|
|
16
17
|
export default pdfEngine;
|
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jackgreen2018/pdf-engine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.105",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"src/"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "wasm-pack build --target bundler && rm -f pkg/.gitignore && tsc",
|
|
22
|
+
"build": "wasm-pack build --target bundler && rm -f pkg/.gitignore && ([ -f src/index.ts ] && tsc || true)",
|
|
23
23
|
"benchmark": "node benchmark.mjs",
|
|
24
24
|
"test": "node tests/smoke.js",
|
|
25
25
|
"prepare": "echo 'skip'"
|
package/pkg/README.md
CHANGED
|
@@ -114,14 +114,14 @@ npm run benchmark
|
|
|
114
114
|
|
|
115
115
|
| Operation | pdf-engine (ms) | pdf-lib (ms) |
|
|
116
116
|
|-----------|-----------------|--------------|
|
|
117
|
-
| Page Count | 0.
|
|
118
|
-
| Text Extraction | 0.
|
|
119
|
-
| Merge (2 files) | 1.
|
|
120
|
-
| Split (pages [0,1]) | 0.
|
|
117
|
+
| Page Count | 0.57 | 1.46 |
|
|
118
|
+
| Text Extraction | 0.22 | — |
|
|
119
|
+
| Merge (2 files) | 1.16 | 4.12 |
|
|
120
|
+
| Split (pages [0,1]) | 0.28 | 1.58 |
|
|
121
121
|
|
|
122
|
-
*extractText correctness: PASS — gated via `tests/fixtures/text-fixture.pdf` (FlateDecode-compressed, real-world content stream)
|
|
122
|
+
*extractText correctness: PASS — gated via `tests/fixtures/text-fixture.pdf` (FlateDecode-compressed, real-world content stream).*
|
|
123
123
|
|
|
124
|
-
*Run 2026-08-03
|
|
124
|
+
*Run 2026-08-03; raw JSON at benchmark-results.json.*
|
|
125
125
|
|
|
126
126
|
## Commercial license & support
|
|
127
127
|
|
package/pkg/package.json
CHANGED
package/pkg/pdf_engine_bg.wasm
CHANGED
|
Binary file
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Jack Green
|
|
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/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAEhD;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtE;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAErE;AAED,wBAAsB,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAGzE;AAED,wBAAsB,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAGtF;AAED,qBAAa,aAAa;IACtB,cAEC;IACD,OAAO,CAAC,WAAW,CAAS;IAEtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAK1B;IAEK,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAGtD;IAEK,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAGrD;IAEK,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAGzD;IAEK,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAGtE;CACJ;AAED,QAAA,MAAM,SAAS,eAAsB,CAAC;eACvB,SAAS"}
|
package/pkg/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Jack Green
|
|
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/src/cli.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import pdfEngine from './index.js';
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
|
|
6
|
-
const USAGE = `pdf-engine — Rust/WASM PDF processing (v${require('../package.json').version})
|
|
7
|
-
|
|
8
|
-
Usage:
|
|
9
|
-
pdf-engine <command> [args]
|
|
10
|
-
|
|
11
|
-
Commands:
|
|
12
|
-
page-count <file> Print the page count of a PDF
|
|
13
|
-
extract-text <file> Extract text from a PDF
|
|
14
|
-
merge <file1> <file2> ... Merge PDFs into a single output
|
|
15
|
-
split <file> <page1> ... Split a PDF by 0-based page indices
|
|
16
|
-
help Print this message
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
async function main(): Promise<number> {
|
|
20
|
-
const [cmd, ...args] = process.argv.slice(2);
|
|
21
|
-
if (!cmd || cmd === '-h' || cmd === '--help' || cmd === 'help') {
|
|
22
|
-
process.stdout.write(USAGE);
|
|
23
|
-
return 0;
|
|
24
|
-
}
|
|
25
|
-
const fs = await import('fs/promises');
|
|
26
|
-
const read = async (p: string) => new Uint8Array(await fs.readFile(p));
|
|
27
|
-
await pdfEngine.init();
|
|
28
|
-
switch (cmd) {
|
|
29
|
-
case 'page-count': {
|
|
30
|
-
const n = await pdfEngine.getPageCount(await read(args[0]));
|
|
31
|
-
process.stdout.write(String(n) + '\n');
|
|
32
|
-
return 0;
|
|
33
|
-
}
|
|
34
|
-
case 'extract-text': {
|
|
35
|
-
const t = await pdfEngine.extractText(await read(args[0]));
|
|
36
|
-
process.stdout.write(t + '\n');
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
39
|
-
case 'merge': {
|
|
40
|
-
const out = await pdfEngine.merge(await Promise.all(args.map(read)));
|
|
41
|
-
await fs.writeFile('merged.pdf', out);
|
|
42
|
-
process.stdout.write(`wrote merged.pdf (${out.byteLength} bytes)\n`);
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
case 'split': {
|
|
46
|
-
const [file, ...pages] = args;
|
|
47
|
-
const out = await pdfEngine.split(
|
|
48
|
-
await read(file),
|
|
49
|
-
pages.map(Number),
|
|
50
|
-
);
|
|
51
|
-
for (let i = 0; i < out.length; i++) {
|
|
52
|
-
await fs.writeFile(`part-${i}.pdf`, out[i]);
|
|
53
|
-
}
|
|
54
|
-
process.stdout.write(`wrote ${out.length} part-*.pdf files\n`);
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
57
|
-
default:
|
|
58
|
-
process.stderr.write(`unknown command: ${cmd}\n${USAGE}`);
|
|
59
|
-
return 1;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
main().then((c) => process.exit(c)).catch((e) => {
|
|
64
|
-
process.stderr.write(String(e) + '\n');
|
|
65
|
-
process.exit(1);
|
|
66
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// PDF Engine TypeScript bindings for Rust/WASM PDF processing library
|
|
2
|
-
|
|
3
|
-
import * as wasm from '../pkg/pdf_engine.js';
|
|
4
|
-
|
|
5
|
-
export async function initialize(): Promise<void> {
|
|
6
|
-
await wasm.init();
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function getPageCount(buffer: Uint8Array): Promise<number> {
|
|
10
|
-
return await wasm.get_page_count(buffer);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function extractText(buffer: Uint8Array): Promise<string> {
|
|
14
|
-
return await wasm.extract_text(buffer);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function merge(pdfBuffers: Uint8Array[]): Promise<Uint8Array> {
|
|
18
|
-
const result = await wasm.merge(pdfBuffers);
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function split(buffer: Uint8Array, pages: number[]): Promise<Uint8Array[]> {
|
|
23
|
-
const resultArray = await wasm.split(buffer, pages);
|
|
24
|
-
return Array.from(resultArray).map(arr => arr as Uint8Array);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class PdfEngineImpl {
|
|
28
|
-
constructor() {
|
|
29
|
-
this.initialized = false;
|
|
30
|
-
}
|
|
31
|
-
private initialized = false;
|
|
32
|
-
|
|
33
|
-
async init(): Promise<void> {
|
|
34
|
-
if (!this.initialized) {
|
|
35
|
-
await initialize();
|
|
36
|
-
this.initialized = true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async getPageCount(buffer: Uint8Array): Promise<number> {
|
|
41
|
-
await this.init();
|
|
42
|
-
return await getPageCount(buffer);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async extractText(buffer: Uint8Array): Promise<string> {
|
|
46
|
-
await this.init();
|
|
47
|
-
return await extractText(buffer);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async merge(pdfBuffers: Uint8Array[]): Promise<Uint8Array> {
|
|
51
|
-
await this.init();
|
|
52
|
-
return await merge(pdfBuffers);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async split(buffer: Uint8Array, pages: number[]): Promise<Uint8Array[]> {
|
|
56
|
-
await this.init();
|
|
57
|
-
return await split(buffer, pages);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const pdfEngine = new PdfEngineImpl();
|
|
62
|
-
export default pdfEngine;
|