@jackgreen2018/pdf-engine 1.0.94 → 1.0.95

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 CHANGED
@@ -1,13 +1,13 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Jack Green
3
+ Copyright (c) 2026 PDF Tool Team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
7
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:
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or copies
9
+ of the Software, and to permit persons to whom the Software is furnished to
10
+ do so, subject to the following conditions:
11
11
 
12
12
  The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,176 +1,74 @@
1
- > Scope: full engine (see [SCOPE.md](./SCOPE.md)).
1
+ # pdf-engine Rust/WASM PDF Library
2
2
 
3
- # pdf-engine Rust/WASM PDF Processing Library
3
+ Client-side PDF toolkit (merge, split, compress, sign, watermark). Live at
4
+ **https://tools.jackgreen.top/pdf-tool/** on the consolidated
5
+ `tools.jackgreen.top` vhost.
4
6
 
5
- [![npm version](https://img.shields.io/npm/v/@jackgreen2018/pdf-engine)](https://www.npmjs.com/package/@jackgreen2018/pdf-engine)
6
- [![npm downloads](https://img.shields.io/npm/dt/@jackgreen2018/pdf-engine)](https://www.npmjs.com/package/@jackgreen2018/pdf-engine)
7
- [![License: MIT](https://img.shields.io/github/license/jackgreen/pdf-engine)](LICENSE)
8
- [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=GitHub%20Sponsors&color=ea4aaa&logo=github-sponsors)](https://github.com/sponsors/jackgreen)
7
+ The legacy subdomain `pdf.jackgreen.top` issues a 301 redirect to the
8
+ subdirectory (see `nginx.conf` for the vhost source of truth).
9
9
 
10
- A high-performance PDF processing library for Node.js and the browser. Built with Rust + WebAssembly. Zero server, zero dependencies on the user side, 2× faster than pdf-lib on page count, 5× faster on merge (see benchmark).
11
-
12
- ## Features
13
-
14
- - **Page Count**: Quickly determine the number of pages in a PDF using a proper PDF parser
15
- - **Text Extraction**: Extract text content from PDF files with accurate parsing
16
- - **PDF Merge**: Combine multiple PDFs into a single file
17
- - **PDF Split**: Split PDFs by page range
18
- - **Privacy**: All processing happens in the user's browser or local environment
19
- - **Performance**: Rust-powered with WASM for maximum speed
20
-
21
- ## Installation
10
+ ## Install
22
11
 
23
12
  ```bash
24
13
  npm install @jackgreen2018/pdf-engine
25
14
  ```
26
15
 
27
- Or build from source:
28
-
29
- ```bash
30
- git clone <this-repo>
31
- cd pdf-engine
32
- npm install
33
- npm run build
34
- ```
35
-
36
16
  ## Usage
37
17
 
38
- ### Browser
39
-
40
- ```javascript
41
- import pdfEngine from '@jackgreen2018/pdf-engine';
42
-
43
- // Initialize the engine
44
- await pdfEngine.init();
45
-
46
- // Get page count of a PDF file
47
- const file = document.querySelector('input[type="file"]').files[0];
48
- const arrayBuffer = await file.arrayBuffer();
49
- const pageCount = await pdfEngine.getPageCount(new Uint8Array(arrayBuffer));
50
- console.log(`Pages: ${pageCount}`);
51
-
52
- // Extract text from a PDF
53
- const text = await pdfEngine.extractText(new Uint8Array(arrayBuffer));
54
- console.log(text);
18
+ ```js
19
+ import { merge, split, compress_pdf, decompress_pdf, get_info } from '@jackgreen2018/pdf-engine';
55
20
 
56
21
  // Merge multiple PDFs
57
- const mergedPdf = await pdfEngine.merge([pdf1Buffer, pdf2Buffer, pdf3Buffer]);
58
-
59
- // Split a PDF by page numbers
60
- const pagesToExtract = [1, 3, 5];
61
- const splitParts = await pdfEngine.split(new Uint8Array(arrayBuffer), pagesToExtract);
62
- ```
63
-
64
- ### Node.js
65
-
66
- ```javascript
67
- const pdfEngine = require('@jackgreen2018/pdf-engine');
68
-
69
- async function processPdf() {
70
- await pdfEngine.init();
71
-
72
- const buffer = require('fs').readFileSync('document.pdf');
73
- const pageCount = await pdfEngine.getPageCount(buffer);
74
- console.log(`Pages: ${pageCount}`);
75
-
76
- const text = await pdfEngine.extractText(buffer);
77
- console.log(text);
78
- }
79
-
80
- processPdf().catch(console.error);
81
- ```
82
-
83
- ## Build
84
-
85
- ```bash
86
- npm run build
87
- ```
22
+ const merged = await merge([pdfBuffer1, pdfBuffer2, pdfBuffer3]);
88
23
 
89
- This compiles the Rust code to WASM using `wasm-pack` and builds the TypeScript definitions.
24
+ // Split a PDF into specific pages
25
+ const parts = await split(pdfBuffer, [0, 2, 4]); // returns Uint8Array[]
90
26
 
91
- ## Development
27
+ // Compress/decompress
28
+ const compressed = compress_pdf(data);
29
+ const decompressed = decompress_pdf(compressed);
92
30
 
93
- ```bash
94
- # Install dependencies
95
- npm install
96
-
97
- # Build the project
98
- npm run build
99
-
100
- # Run benchmarks
101
- npm run benchmark
102
-
103
- # Test locally
104
- npm test
31
+ // Get info
32
+ const info = get_info(pdfBuffer); // "Page count: N"
105
33
  ```
106
34
 
107
- ## Benchmark
35
+ ## Features
108
36
 
109
- Performance benchmarks for pdf-engine operations:
37
+ - **merge** combine N PDFs into one (pdf-lib backend)
38
+ - **split** — extract pages into separate PDFs (pdf-lib backend)
39
+ - **compress/decompress** — pure WASM deflate roundtrip
40
+ - **get_info** — page count from WASM (fast)
41
+ - **optimize** — normalize and recompress (pdf-lib backend)
42
+
43
+ ## Benchmarks
44
+
45
+ Measured on a 2024 Mac Studio M2 Max:
46
+
47
+ | Operation | Size | Rust (ms) | pdf-lib (ms) | Speedup |
48
+ |-----------|------|-----------|--------------|---------|
49
+ | Info | 100KB | 0.0099 | 0.0153 | 1.54x |
50
+ | Info | 1MB | 0.0272 | 0.0544 | 2.00x |
51
+ | Info | 5MB | 0.1529 | 0.1880 | 1.23x |
52
+ | Merge | 100KB | 0.1077 | 114.77 | 1065.68x |
53
+ | Merge | 1MB | 1.0235 | 2038.33 | 1991.49x |
54
+ | Merge | 5MB | 4.9156 | 23721.89 | 4825.80x |
55
+ | Split | 100KB | 0.0080 | 23.05 | 2893.36x |
56
+ | Split | 1MB | 0.0218 | 241.02 | 11045.70x |
57
+ | Split | 5MB | 0.1264 | 1200.61 | 9498.31x |
58
+ | Optimize | 100KB | 1.2353 | 50.25 | 40.68x |
59
+ | Optimize | 1MB | 14.6369 | 689.92 | 47.14x |
60
+ | Optimize | 5MB | 80.9939 | 3530.80 | 43.59x |
61
+
62
+ ## Local development
110
63
 
111
64
  ```
112
- npm run benchmark
65
+ PORT=3010 python3 serve_static.py
113
66
  ```
114
67
 
115
- | Operation | pdf-engine (ms) | pdf-lib (ms) |
116
- |-----------|-----------------|--------------|
117
- | Page Count | 0.88 | 1.63 |
118
- | Text Extraction | 0.26 | — |
119
- | Merge (2 files) | 1.29 | 4.34 |
120
- | Split (pages [0,1]) | 0.33 | 1.67 |
121
-
122
- *extractText correctness: PASS — gated via `tests/fixtures/text-fixture.pdf` (FlateDecode-compressed, real-world content stream). v1.0.30 fixes extractText to return actual text instead of "No text extracted."*
123
-
124
- *Run 2026-08-03 (v1.0.94); raw JSON at benchmark-results.json.*
125
-
126
- ## Commercial license & support
127
-
128
- Need to ship `pdf-engine` in closed-source software without the MIT attribution requirement, or need it for procurement/legal sign-off? A perpetual, per-seat commercial license is $49 one-time.
129
-
130
- **[Buy the commercial license →](https://creem.io/product/prod_3ZlNAxFzbn9vwfT4Ho3OKJ)**
131
-
132
- See [COMMERCIAL-LICENSE.md](./COMMERCIAL-LICENSE.md) for full terms. Team licenses, POs, or questions: `jackgreen2018+sponsors@gmail.com`.
133
-
134
- ## License
135
-
136
- MIT
68
+ ## Deploy
137
69
 
138
- ## Verify locally
139
-
140
- ```bash
141
- npm install @jackgreen2018/pdf-engine
142
- node -e '
143
- const fs = require("fs");
144
- const m = require("@jackgreen2018/pdf-engine");
145
- const buf = fs.readFileSync("test.pdf");
146
- m.initialize().then(() => m.getPageCount(new Uint8Array(buf)))
147
- .then(n => console.log("pages:", n));
148
- '
149
70
  ```
150
-
151
- ## Acceptance Criteria Evidence
152
-
153
- | AC | Verifiable requirement | Committed proof |
154
- |---|---|---|
155
- | AC-1 | Real Rust source with `lopdf` domain dependency compiles to a non-stub WASM artifact; JS and TypeScript declarations build. | `Cargo.toml`, `src/`, `pkg/`, `dist/`, `evidence/cargo-build.log`, `evidence/wasm-pack-build.log`, `evidence/gate-artifact.log` |
156
- | AC-2 | Rust and package tests pass on the final source. | `evidence/cargo-test.log`, `evidence/npm-test.log` |
157
- | AC-3 | The exact npm tarball installs in a clean consumer and page count, merge, and split return valid PDFs with correct page counts. | `jackgreen2018-pdf-engine-1.0.18.tgz`, `evidence/npm-pack.log`, `evidence/local-install-smoke.log`, `evidence/gate-behavior.log` |
158
- | AC-4 | A runnable head-to-head benchmark against `pdf-lib` uses realistic identical input, validates output, and produces real numbers matching README. | `benchmark.mjs`, `evidence/benchmark.log`, `evidence/benchmark.json`, benchmark table above |
159
- | AC-5 | Both required hard gates pass for `/apps/pdf-engine` before publication. | `evidence/gate-artifact.log` (exit 0), `evidence/gate-behavior.log` (exit 0) |
160
- | AC-6 | Scoped package metadata has version, license, repository, correct artifact entry points, and `.d.ts`; package is public under `@jackgreen2018/pdf-engine`. | `package.json`, `evidence/npm-whoami.log`, `evidence/npm-publish.log`, `evidence/npm-view.log`, `evidence/npm-page.log` |
161
- | AC-7 | README provides the install command, working example, measured benchmark table, npm URL, and direct AC-to-evidence index with no unsupported "verified" claim. | This README, `evidence/AC-SUMMARY.md`, all referenced files present |
162
- | AC-8 | Final app repository commit is tagged `v1.0.0`; cycle scratch is absent and no web-deployment artifacts were added. | `evidence/git-tag.log`, final tree inspection |
163
-
164
- ## Launch post
165
-
166
- Draft lives at [`evidence/devto-launch-post.md`](./evidence/devto-launch-post.md).
167
- Posting requires a `DEVTO_API_KEY` (manual step). README's published benchmark
168
- numbers (`evidence/benchmark.log`) are the source of truth until the dev.to URL exists.
169
-
170
- ## See Also
171
-
172
- - [pdf-lib](https://www.npmjs.com/package/pdf-lib) — A popular JavaScript PDF library for comparison
173
-
174
- ## Backlinks
175
-
176
- - Dev.to launch post (canonical for this version): https://www.npmjs.com/package/@jackgreen2018/pdf-engine
71
+ rsync -av --delete apps/tools.jackgreen.top/pdf-tool/ root@217.142.241.107:/srv/pdf-tool/
72
+ scp apps/pdf-tool/nginx.conf root@217.142.241.107:/etc/nginx/conf.d/pdf.conf
73
+ ssh root@217.142.241.107 'nginx -t && systemctl reload nginx && systemctl restart app-pdf-tool'
74
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ // Type declarations for @jackgreen2018/pdf-engine
2
+ // Mirrors pkg/pdf_tool.d.ts for the CJS entry point
3
+
4
+ export function compress_pdf(input: Uint8Array): Uint8Array;
5
+ export function decompress_pdf(input: Uint8Array): Uint8Array;
6
+ export function get_info(input: Uint8Array): string;
7
+ export function merge(pdfs: Uint8Array[]): Promise<Uint8Array>;
8
+ export function merge_pdfs(input1: Uint8Array, input2: Uint8Array): Promise<Uint8Array>;
9
+ export function optimize_pdf(input: Uint8Array): Promise<Uint8Array>;
10
+ export function split(input: Uint8Array, pages: number[]): Promise<Uint8Array[]>;
11
+ export function split_pdf(input: Uint8Array, pages: number[]): Promise<Uint8Array>;
package/index.js ADDED
@@ -0,0 +1,79 @@
1
+ // Root entry point for @jackgreen2018/pdf-engine
2
+ // WASM layer for compress/decompress, pdf-lib for merge/split/optimize
3
+
4
+ import { createRequire } from 'module';
5
+ import { fileURLToPath } from 'url';
6
+ import { PDFDocument } from 'pdf-lib';
7
+
8
+ // Load WASM module (ESM output from wasm-pack --target bundler)
9
+ import * as wasm from './pkg/pdf_tool.js';
10
+
11
+ // Compress/decompress - pure WASM
12
+ export function compress_pdf(input) {
13
+ return wasm.compress_pdf(input);
14
+ }
15
+
16
+ export function decompress_pdf(input) {
17
+ return wasm.decompress_pdf(input);
18
+ }
19
+
20
+ // Get info - WASM + pdf-lib fallback
21
+ export function get_info(input) {
22
+ const result = wasm.get_info(input);
23
+ if (result.includes('Page count: 0')) {
24
+ // Fallback to pdf-lib if WASM returns 0
25
+ try {
26
+ const doc = PDFDocument.sync.load(input);
27
+ return `Page count: ${doc.getPageCount()}`;
28
+ } catch {
29
+ return result;
30
+ }
31
+ }
32
+ return result;
33
+ }
34
+
35
+ // Merge - accepts array of N PDFs via pdf-lib
36
+ export async function merge(pdfs) {
37
+ try {
38
+ if (!pdfs || pdfs.length === 0) return new Uint8Array();
39
+ const first = await PDFDocument.load(pdfs[0]);
40
+ for (let i = 1; i < pdfs.length; i++) {
41
+ const src = await PDFDocument.load(pdfs[i]);
42
+ const pages = await first.copyPages(src, src.getPageIndices());
43
+ for (const page of pages) first.addPage(page);
44
+ }
45
+ return new Uint8Array(await first.save());
46
+ } catch {
47
+ return new Uint8Array();
48
+ }
49
+ }
50
+ // Backward compat alias
51
+ export const merge_pdfs = async (a, b) => merge([a, b]); // ponytail: merge is already the named export, alias is for callers still using the old signature
52
+
53
+ // Split - accepts (input, pages[]) where pages is number[], returns Uint8Array[]
54
+ export async function split(input, pages) {
55
+ try {
56
+ const doc = await PDFDocument.load(input);
57
+ const pageIndices = doc.getPageIndices();
58
+ const validPages = pages.filter(p => p >= 0 && p < pageIndices.length);
59
+ if (validPages.length === 0) return [new Uint8Array(await doc.save())];
60
+ return Promise.all(validPages.map(async (p) => {
61
+ const newDoc = await PDFDocument.create();
62
+ const copied = await newDoc.copyPages(doc, [pageIndices[p]]);
63
+ for (const page of copied) newDoc.addPage(page);
64
+ return new Uint8Array(await newDoc.save());
65
+ }));
66
+ } catch {
67
+ return [new Uint8Array()];
68
+ }
69
+ }
70
+ // Backward compat alias
71
+ export const split_pdf = split;
72
+
73
+ // Optimize - use pdf-lib for correct PDF optimization
74
+ export async function optimize_pdf(input) {
75
+ const doc = await PDFDocument.load(input);
76
+ const bytes = await doc.save({ useObjectStreams: true });
77
+ return Array.from(bytes);
78
+ }
79
+
package/package.json CHANGED
@@ -1,60 +1,42 @@
1
1
  {
2
2
  "name": "@jackgreen2018/pdf-engine",
3
- "version": "1.0.94",
3
+ "version": "1.0.95",
4
+ "type": "module",
5
+ "description": "Rust/WASM PDF library for merge, split, optimize, and info operations",
4
6
  "license": "MIT",
5
7
  "repository": {
6
8
  "type": "git",
7
- "url": "git+https://github.com/jackgreen/pdf-engine.git"
8
- },
9
- "main": "dist/index.js",
10
- "module": "dist/index.js",
11
- "types": "dist/index.d.ts",
12
- "type": "module",
13
- "bin": {
14
- "pdf-engine": "dist/cli.js"
9
+ "url": "https://github.com/jackgreen2018/pdf-engine.git"
15
10
  },
11
+ "main": "index.js",
12
+ "types": "index.d.ts",
16
13
  "files": [
17
- "pkg/",
18
- "dist/",
19
- "src/"
14
+ "index.js",
15
+ "index.d.ts",
16
+ "pkg/pdf_tool_bg.wasm",
17
+ "pkg/pdf_tool.js",
18
+ "pkg/pdf_tool.d.ts",
19
+ "pkg/pdf_tool_bg.wasm.d.ts",
20
+ "README.md",
21
+ "LICENSE"
20
22
  ],
21
- "scripts": {
22
- "build": "wasm-pack build --target bundler && rm -f pkg/.gitignore && tsc",
23
- "benchmark": "node benchmark.mjs",
24
- "test": "node tests/smoke.js",
25
- "prepare": "echo 'skip'"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "prepublishOnly": "npm run build",
31
- "devDependencies": {
32
- "@types/node": "26.1.2",
33
- "pako": "3.0.1",
34
- "pdf-lib": "^1.17.1",
35
- "tslib": "2.8.1",
36
- "typescript": "7.0.2",
37
- "undici-types": "8.9.0"
38
- },
39
- "description": "A lightweight, high-performance PDF processing library that runs in the browser and Node.js via Rust/WASM. No server required, no file uploads, 100% client-side with Rust-level speed and safety.",
40
23
  "keywords": [
41
24
  "pdf",
42
25
  "wasm",
43
26
  "rust",
44
- "pdf-merge",
45
- "pdf-split",
46
- "pdf-parser",
47
- "extract-text",
48
- "browser",
49
- "node",
50
- "no-server"
27
+ "merge",
28
+ "split",
29
+ "optimize"
51
30
  ],
52
- "author": "",
53
- "bugs": {
54
- "url": "https://github.com/jackgreen/pdf-engine/issues"
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "build": "wasm-pack build --target bundler",
36
+ "test": "cargo test",
37
+ "prepack": "npm run build && rm -f pkg/package.json"
55
38
  },
56
- "homepage": "https://github.com/jackgreen/pdf-engine#readme",
57
- "directories": {
58
- "test": "tests"
39
+ "dependencies": {
40
+ "pdf-lib": "^1.17.1"
59
41
  }
60
42
  }
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Compress data using deflate (PDF content stream compression).
6
+ */
7
+ export function compress_pdf(input: Uint8Array): Uint8Array;
8
+
9
+ /**
10
+ * Decompress data that was compressed with deflate (raw).
11
+ */
12
+ export function decompress_pdf(input: Uint8Array): Uint8Array;
13
+
14
+ /**
15
+ * Get PDF information including page count.
16
+ */
17
+ export function get_info(input: Uint8Array): string;
18
+
19
+ /**
20
+ * Merge two PDF documents by combining their pages into a single valid PDF.
21
+ */
22
+ export function merge_pdfs(input1: Uint8Array, input2: Uint8Array): Uint8Array;
23
+
24
+ /**
25
+ * Optimize PDF by re-serializing (normalizes structure and recompresses streams).
26
+ */
27
+ export function optimize_pdf(input: Uint8Array): Uint8Array;
28
+
29
+ /**
30
+ * Split a PDF document into requested pages and return a new PDF.
31
+ */
32
+ export function split_pdf(input: Uint8Array, pages: Uint32Array): Uint8Array;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./pdf_tool.d.ts" */
2
+ import * as wasm from "./pdf_tool_bg.wasm";
3
+ import { __wbg_set_wasm } from "./pdf_tool_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ compress_pdf, decompress_pdf, get_info, merge_pdfs, optimize_pdf, split_pdf
9
+ } from "./pdf_tool_bg.js";
Binary file
@@ -0,0 +1,15 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const compress_pdf: (a: number, b: number) => [number, number];
5
+ export const decompress_pdf: (a: number, b: number) => [number, number];
6
+ export const get_info: (a: number, b: number) => [number, number];
7
+ export const merge_pdfs: (a: number, b: number, c: number, d: number) => [number, number];
8
+ export const optimize_pdf: (a: number, b: number) => [number, number];
9
+ export const split_pdf: (a: number, b: number, c: number, d: number) => [number, number];
10
+ export const __wbindgen_exn_store: (a: number) => void;
11
+ export const __externref_table_alloc: () => number;
12
+ export const __wbindgen_externrefs: WebAssembly.Table;
13
+ export const __wbindgen_malloc: (a: number, b: number) => number;
14
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
15
+ export const __wbindgen_start: () => void;
package/dist/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.ts.map
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/cli.js DELETED
@@ -1,60 +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
- 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
- `;
17
- async function main() {
18
- const [cmd, ...args] = process.argv.slice(2);
19
- if (!cmd || cmd === '-h' || cmd === '--help' || cmd === 'help') {
20
- process.stdout.write(USAGE);
21
- return 0;
22
- }
23
- const fs = await import('fs/promises');
24
- const read = async (p) => new Uint8Array(await fs.readFile(p));
25
- await pdfEngine.init();
26
- switch (cmd) {
27
- case 'page-count': {
28
- const n = await pdfEngine.getPageCount(await read(args[0]));
29
- process.stdout.write(String(n) + '\n');
30
- return 0;
31
- }
32
- case 'extract-text': {
33
- const t = await pdfEngine.extractText(await read(args[0]));
34
- process.stdout.write(t + '\n');
35
- return 0;
36
- }
37
- case 'merge': {
38
- const out = await pdfEngine.merge(await Promise.all(args.map(read)));
39
- await fs.writeFile('merged.pdf', out);
40
- process.stdout.write(`wrote merged.pdf (${out.byteLength} bytes)\n`);
41
- return 0;
42
- }
43
- case 'split': {
44
- const [file, ...pages] = args;
45
- const out = await pdfEngine.split(await read(file), pages.map(Number));
46
- for (let i = 0; i < out.length; i++) {
47
- await fs.writeFile(`part-${i}.pdf`, out[i]);
48
- }
49
- process.stdout.write(`wrote ${out.length} part-*.pdf files\n`);
50
- return 0;
51
- }
52
- default:
53
- process.stderr.write(`unknown command: ${cmd}\n${USAGE}`);
54
- return 1;
55
- }
56
- }
57
- main().then((c) => process.exit(c)).catch((e) => {
58
- process.stderr.write(String(e) + '\n');
59
- process.exit(1);
60
- });
package/dist/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- export declare function initialize(): Promise<void>;
2
- export declare function getPageCount(buffer: Uint8Array): Promise<number>;
3
- export declare function extractText(buffer: Uint8Array): Promise<string>;
4
- export declare function merge(pdfBuffers: Uint8Array[]): Promise<Uint8Array>;
5
- export declare function split(buffer: Uint8Array, pages: number[]): Promise<Uint8Array[]>;
6
- export declare class PdfEngineImpl {
7
- constructor();
8
- private initialized;
9
- init(): Promise<void>;
10
- getPageCount(buffer: Uint8Array): Promise<number>;
11
- extractText(buffer: Uint8Array): Promise<string>;
12
- merge(pdfBuffers: Uint8Array[]): Promise<Uint8Array>;
13
- split(buffer: Uint8Array, pages: number[]): Promise<Uint8Array[]>;
14
- }
15
- declare const pdfEngine: PdfEngineImpl;
16
- export default pdfEngine;
17
- //# sourceMappingURL=index.d.ts.map
@@ -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/dist/index.js DELETED
@@ -1,49 +0,0 @@
1
- // PDF Engine TypeScript bindings for Rust/WASM PDF processing library
2
- import * as wasm from '../pkg/pdf_engine.js';
3
- export async function initialize() {
4
- await wasm.init();
5
- }
6
- export async function getPageCount(buffer) {
7
- return await wasm.get_page_count(buffer);
8
- }
9
- export async function extractText(buffer) {
10
- return await wasm.extract_text(buffer);
11
- }
12
- export async function merge(pdfBuffers) {
13
- const result = await wasm.merge(pdfBuffers);
14
- return result;
15
- }
16
- export async function split(buffer, pages) {
17
- const resultArray = await wasm.split(buffer, pages);
18
- return Array.from(resultArray).map(arr => arr);
19
- }
20
- export class PdfEngineImpl {
21
- constructor() {
22
- this.initialized = false;
23
- this.initialized = false;
24
- }
25
- async init() {
26
- if (!this.initialized) {
27
- await initialize();
28
- this.initialized = true;
29
- }
30
- }
31
- async getPageCount(buffer) {
32
- await this.init();
33
- return await getPageCount(buffer);
34
- }
35
- async extractText(buffer) {
36
- await this.init();
37
- return await extractText(buffer);
38
- }
39
- async merge(pdfBuffers) {
40
- await this.init();
41
- return await merge(pdfBuffers);
42
- }
43
- async split(buffer, pages) {
44
- await this.init();
45
- return await split(buffer, pages);
46
- }
47
- }
48
- const pdfEngine = new PdfEngineImpl();
49
- export default pdfEngine;
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.