@jackgreen2018/pdf-engine 1.0.89 → 1.0.91
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 +12 -162
- package/index.d.ts +11 -0
- package/index.js +79 -0
- package/package.json +22 -45
- package/pkg/pdf_tool.d.ts +32 -0
- package/pkg/pdf_tool.js +193 -0
- package/pkg/pdf_tool_bg.wasm +0 -0
- package/pkg/pdf_tool_bg.wasm.d.ts +15 -0
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -60
- package/dist/index.d.ts +0 -17
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -49
- package/pkg/README.md +0 -172
- package/pkg/package.json +0 -16
- package/pkg/pdf_engine.d.ts +0 -14
- package/pkg/pdf_engine.js +0 -9
- package/pkg/pdf_engine_bg.js +0 -220
- package/pkg/pdf_engine_bg.wasm +0 -0
- package/pkg/pdf_engine_bg.wasm.d.ts +0 -14
- package/src/cli.ts +0 -66
- package/src/index.ts +0 -62
- package/src/lib.rs +0 -294
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PDF Tool Team
|
|
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 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
|
+
|
|
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
CHANGED
|
@@ -1,172 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
# pdf-tool — Consolidated
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
[](LICENSE)
|
|
8
|
-
[](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
|
-
|
|
10
|
+
## Local development
|
|
11
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
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @jackgreen2018/pdf-engine
|
|
25
|
-
```
|
|
26
|
-
|
|
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
|
-
## Usage
|
|
37
|
-
|
|
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);
|
|
55
|
-
|
|
56
|
-
// 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
12
|
```
|
|
88
|
-
|
|
89
|
-
This compiles the Rust code to WASM using `wasm-pack` and builds the TypeScript definitions.
|
|
90
|
-
|
|
91
|
-
## Development
|
|
92
|
-
|
|
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
|
|
13
|
+
PORT=3010 python3 serve_static.py
|
|
105
14
|
```
|
|
106
15
|
|
|
107
|
-
##
|
|
108
|
-
|
|
109
|
-
Performance benchmarks for pdf-engine operations:
|
|
16
|
+
## Deploy
|
|
110
17
|
|
|
111
18
|
```
|
|
112
|
-
|
|
19
|
+
rsync -av --delete apps/tools.jackgreen.top/pdf-tool/ root@217.142.241.107:/srv/pdf-tool/
|
|
20
|
+
scp apps/pdf-tool/nginx.conf root@217.142.241.107:/etc/nginx/conf.d/pdf.conf
|
|
21
|
+
ssh root@217.142.241.107 'nginx -t && systemctl reload nginx && systemctl restart app-pdf-tool'
|
|
113
22
|
```
|
|
114
|
-
|
|
115
|
-
| Operation | pdf-engine (ms) | pdf-lib (ms) |
|
|
116
|
-
|-----------|-----------------|--------------|
|
|
117
|
-
| Page Count | 0.77 | 1.46 |
|
|
118
|
-
| Text Extraction | 0.33 | — |
|
|
119
|
-
| Merge (2 files) | 1.14 | 4.70 |
|
|
120
|
-
| Split (pages [0,1]) | 0.32 | 2.02 |
|
|
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.89); raw JSON at benchmark-results.json.*
|
|
125
|
-
|
|
126
|
-
## Commercial license & support
|
|
127
|
-
|
|
128
|
-
For teams or organizations that need the package without MIT attribution obligations, or require a formal SLA, a commercial license is available. See [COMMERCIAL-LICENSE.md](./COMMERCIAL-LICENSE.md) for pricing and terms. To purchase, email `jackgreen2018+sponsors@gmail.com`.
|
|
129
|
-
|
|
130
|
-
## License
|
|
131
|
-
|
|
132
|
-
MIT
|
|
133
|
-
|
|
134
|
-
## Verify locally
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
npm install @jackgreen2018/pdf-engine
|
|
138
|
-
node -e '
|
|
139
|
-
const fs = require("fs");
|
|
140
|
-
const m = require("@jackgreen2018/pdf-engine");
|
|
141
|
-
const buf = fs.readFileSync("test.pdf");
|
|
142
|
-
m.initialize().then(() => m.getPageCount(new Uint8Array(buf)))
|
|
143
|
-
.then(n => console.log("pages:", n));
|
|
144
|
-
'
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## Acceptance Criteria Evidence
|
|
148
|
-
|
|
149
|
-
| AC | Verifiable requirement | Committed proof |
|
|
150
|
-
|---|---|---|
|
|
151
|
-
| 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` |
|
|
152
|
-
| AC-2 | Rust and package tests pass on the final source. | `evidence/cargo-test.log`, `evidence/npm-test.log` |
|
|
153
|
-
| 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` |
|
|
154
|
-
| 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 |
|
|
155
|
-
| 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) |
|
|
156
|
-
| 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` |
|
|
157
|
-
| 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 |
|
|
158
|
-
| 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 |
|
|
159
|
-
|
|
160
|
-
## Launch post
|
|
161
|
-
|
|
162
|
-
Draft lives at [`evidence/devto-launch-post.md`](./evidence/devto-launch-post.md).
|
|
163
|
-
Posting requires a `DEVTO_API_KEY` (manual step). README's published benchmark
|
|
164
|
-
numbers (`evidence/benchmark.log`) are the source of truth until the dev.to URL exists.
|
|
165
|
-
|
|
166
|
-
## See Also
|
|
167
|
-
|
|
168
|
-
- [pdf-lib](https://www.npmjs.com/package/pdf-lib) — A popular JavaScript PDF library for comparison
|
|
169
|
-
|
|
170
|
-
## Backlinks
|
|
171
|
-
|
|
172
|
-
- Dev.to launch post (canonical for this version): https://www.npmjs.com/package/@jackgreen2018/pdf-engine
|
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 { PDFDocument } from 'pdf-lib';
|
|
5
|
+
|
|
6
|
+
// Load WASM module
|
|
7
|
+
const wasmPath = new URL('./pkg/pdf_tool.js', import.meta.url).pathname;
|
|
8
|
+
const wasmModule = await import(wasmPath);
|
|
9
|
+
const wasm = wasmModule.default || wasmModule;
|
|
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,62 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jackgreen2018/pdf-engine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.91",
|
|
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": "
|
|
8
|
-
},
|
|
9
|
-
"main": "dist/index.js",
|
|
10
|
-
"module": "dist/index.mjs",
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
12
|
-
"type": "module",
|
|
13
|
-
"bin": {
|
|
14
|
-
"pdf-engine": "dist/cli.js"
|
|
9
|
+
"url": "https://github.com/sapiens-ai/pdf-tool.git"
|
|
15
10
|
},
|
|
11
|
+
"main": "index.js",
|
|
12
|
+
"types": "index.d.ts",
|
|
16
13
|
"files": [
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
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": "npm run build"
|
|
26
|
-
},
|
|
27
|
-
"publishConfig": {
|
|
28
|
-
"access": "public"
|
|
29
|
-
},
|
|
30
|
-
"prepublishOnly": "npm run build",
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"@types/node": "^26.1.2",
|
|
33
|
-
"pdf-lib": "^1.17.1",
|
|
34
|
-
"typescript": "^7.0.2"
|
|
35
|
-
},
|
|
36
|
-
"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.",
|
|
37
23
|
"keywords": [
|
|
38
24
|
"pdf",
|
|
39
25
|
"wasm",
|
|
40
26
|
"rust",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"extract-text",
|
|
45
|
-
"browser",
|
|
46
|
-
"node",
|
|
47
|
-
"no-server"
|
|
27
|
+
"merge",
|
|
28
|
+
"split",
|
|
29
|
+
"optimize"
|
|
48
30
|
],
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
"homepage": "https://github.com/jackgreen/pdf-engine#readme",
|
|
54
|
-
"directories": {
|
|
55
|
-
"test": "tests"
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "wasm-pack build --target nodejs",
|
|
33
|
+
"test": "cargo test",
|
|
34
|
+
"prepack": "npm run build && rm -f pkg/package.json"
|
|
56
35
|
},
|
|
57
36
|
"dependencies": {
|
|
58
|
-
"
|
|
59
|
-
"tslib": "^1.14.1",
|
|
60
|
-
"undici-types": "^8.3.0"
|
|
37
|
+
"pdf-lib": "^1.17.1"
|
|
61
38
|
}
|
|
62
39
|
}
|
|
@@ -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;
|
package/pkg/pdf_tool.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/* @ts-self-types="./pdf_tool.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compress data using deflate (PDF content stream compression).
|
|
5
|
+
* @param {Uint8Array} input
|
|
6
|
+
* @returns {Uint8Array}
|
|
7
|
+
*/
|
|
8
|
+
function compress_pdf(input) {
|
|
9
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
10
|
+
const len0 = WASM_VECTOR_LEN;
|
|
11
|
+
const ret = wasm.compress_pdf(ptr0, len0);
|
|
12
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
13
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
14
|
+
return v2;
|
|
15
|
+
}
|
|
16
|
+
exports.compress_pdf = compress_pdf;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Decompress data that was compressed with deflate (raw).
|
|
20
|
+
* @param {Uint8Array} input
|
|
21
|
+
* @returns {Uint8Array}
|
|
22
|
+
*/
|
|
23
|
+
function decompress_pdf(input) {
|
|
24
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
25
|
+
const len0 = WASM_VECTOR_LEN;
|
|
26
|
+
const ret = wasm.decompress_pdf(ptr0, len0);
|
|
27
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
28
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
29
|
+
return v2;
|
|
30
|
+
}
|
|
31
|
+
exports.decompress_pdf = decompress_pdf;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get PDF information including page count.
|
|
35
|
+
* @param {Uint8Array} input
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
function get_info(input) {
|
|
39
|
+
let deferred2_0;
|
|
40
|
+
let deferred2_1;
|
|
41
|
+
try {
|
|
42
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
43
|
+
const len0 = WASM_VECTOR_LEN;
|
|
44
|
+
const ret = wasm.get_info(ptr0, len0);
|
|
45
|
+
deferred2_0 = ret[0];
|
|
46
|
+
deferred2_1 = ret[1];
|
|
47
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
48
|
+
} finally {
|
|
49
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.get_info = get_info;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Merge two PDF documents by combining their pages into a single valid PDF.
|
|
56
|
+
* @param {Uint8Array} input1
|
|
57
|
+
* @param {Uint8Array} input2
|
|
58
|
+
* @returns {Uint8Array}
|
|
59
|
+
*/
|
|
60
|
+
function merge_pdfs(input1, input2) {
|
|
61
|
+
const ptr0 = passArray8ToWasm0(input1, wasm.__wbindgen_malloc);
|
|
62
|
+
const len0 = WASM_VECTOR_LEN;
|
|
63
|
+
const ptr1 = passArray8ToWasm0(input2, wasm.__wbindgen_malloc);
|
|
64
|
+
const len1 = WASM_VECTOR_LEN;
|
|
65
|
+
const ret = wasm.merge_pdfs(ptr0, len0, ptr1, len1);
|
|
66
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
67
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
68
|
+
return v3;
|
|
69
|
+
}
|
|
70
|
+
exports.merge_pdfs = merge_pdfs;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Optimize PDF by re-serializing (normalizes structure and recompresses streams).
|
|
74
|
+
* @param {Uint8Array} input
|
|
75
|
+
* @returns {Uint8Array}
|
|
76
|
+
*/
|
|
77
|
+
function optimize_pdf(input) {
|
|
78
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
79
|
+
const len0 = WASM_VECTOR_LEN;
|
|
80
|
+
const ret = wasm.optimize_pdf(ptr0, len0);
|
|
81
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
82
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
83
|
+
return v2;
|
|
84
|
+
}
|
|
85
|
+
exports.optimize_pdf = optimize_pdf;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Split a PDF document into requested pages and return a new PDF.
|
|
89
|
+
* @param {Uint8Array} input
|
|
90
|
+
* @param {Uint32Array} pages
|
|
91
|
+
* @returns {Uint8Array}
|
|
92
|
+
*/
|
|
93
|
+
function split_pdf(input, pages) {
|
|
94
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
95
|
+
const len0 = WASM_VECTOR_LEN;
|
|
96
|
+
const ptr1 = passArray32ToWasm0(pages, wasm.__wbindgen_malloc);
|
|
97
|
+
const len1 = WASM_VECTOR_LEN;
|
|
98
|
+
const ret = wasm.split_pdf(ptr0, len0, ptr1, len1);
|
|
99
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
100
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
101
|
+
return v3;
|
|
102
|
+
}
|
|
103
|
+
exports.split_pdf = split_pdf;
|
|
104
|
+
function __wbg_get_imports() {
|
|
105
|
+
const import0 = {
|
|
106
|
+
__proto__: null,
|
|
107
|
+
__wbg_getRandomValues_cc7f052a444bb2ce: function() { return handleError(function (arg0, arg1) {
|
|
108
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
109
|
+
}, arguments); },
|
|
110
|
+
__wbindgen_init_externref_table: function() {
|
|
111
|
+
const table = wasm.__wbindgen_externrefs;
|
|
112
|
+
const offset = table.grow(4);
|
|
113
|
+
table.set(0, undefined);
|
|
114
|
+
table.set(offset + 0, undefined);
|
|
115
|
+
table.set(offset + 1, null);
|
|
116
|
+
table.set(offset + 2, true);
|
|
117
|
+
table.set(offset + 3, false);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
__proto__: null,
|
|
122
|
+
"./pdf_tool_bg.js": import0,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function addToExternrefTable0(obj) {
|
|
127
|
+
const idx = wasm.__externref_table_alloc();
|
|
128
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
129
|
+
return idx;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
133
|
+
ptr = ptr >>> 0;
|
|
134
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function getStringFromWasm0(ptr, len) {
|
|
138
|
+
return decodeText(ptr >>> 0, len);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let cachedUint32ArrayMemory0 = null;
|
|
142
|
+
function getUint32ArrayMemory0() {
|
|
143
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
144
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
145
|
+
}
|
|
146
|
+
return cachedUint32ArrayMemory0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let cachedUint8ArrayMemory0 = null;
|
|
150
|
+
function getUint8ArrayMemory0() {
|
|
151
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
152
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
153
|
+
}
|
|
154
|
+
return cachedUint8ArrayMemory0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function handleError(f, args) {
|
|
158
|
+
try {
|
|
159
|
+
return f.apply(this, args);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
const idx = addToExternrefTable0(e);
|
|
162
|
+
wasm.__wbindgen_exn_store(idx);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
167
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
168
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
169
|
+
WASM_VECTOR_LEN = arg.length;
|
|
170
|
+
return ptr;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
174
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
175
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
176
|
+
WASM_VECTOR_LEN = arg.length;
|
|
177
|
+
return ptr;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
181
|
+
cachedTextDecoder.decode();
|
|
182
|
+
function decodeText(ptr, len) {
|
|
183
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let WASM_VECTOR_LEN = 0;
|
|
187
|
+
|
|
188
|
+
const wasmPath = `${__dirname}/pdf_tool_bg.wasm`;
|
|
189
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
190
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
191
|
+
let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
|
|
192
|
+
let wasm = wasmInstance.exports;
|
|
193
|
+
wasm.__wbindgen_start();
|
|
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
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|