@jackgreen2018/pdf-engine 1.0.44 → 1.0.45

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
@@ -55,7 +55,7 @@ optimize_pdf (50 pages): 0.841 ms
55
55
  get_pdf_info (50 pages): 0.609 ms
56
56
  ```
57
57
 
58
- Run 2026-08-01 (v1.0.44); full stdout at evidence/benchmark-v1.0.44.log; raw results at benchmark-results.txt.
58
+ Run 2026-08-01 (v1.0.45); full stdout at evidence/benchmark-v1.0.45.log; raw results at benchmark-results.txt.
59
59
 
60
60
  ## License
61
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackgreen2018/pdf-engine",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "Rust/WASM PDF library for merge, split, optimize and info operations",
5
5
  "license": "MIT",
6
6
  "repository": {
package/pkg/LICENSE ADDED
@@ -0,0 +1,21 @@
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/pkg/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @jackgreen2018/pdf-engine
2
+
3
+ Rust/WASM PDF library for merge, split, optimize and info operations.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @jackgreen2018/pdf-engine
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ const { init, merge_pdfs, split_pdf, get_page_count, get_pdf_info, optimize_pdf } = require('@jackgreen2018/pdf-engine');
15
+
16
+ async function example() {
17
+ await init();
18
+
19
+ // Merge two PDFs
20
+ const merged = merge_pdfs(pdfBuffer1, pdfBuffer2);
21
+
22
+ // Split a PDF (extract pages 1, 3, 5)
23
+ const split = split_pdf(inputPdf, [1, 3, 5]);
24
+
25
+ // Get page count
26
+ const count = get_page_count(pdfBuffer);
27
+
28
+ // Get PDF metadata
29
+ const info = get_pdf_info(pdfBuffer);
30
+ // Returns: { version, pageCount, Title, Author, ... }
31
+
32
+ // Optimize a PDF
33
+ const optimized = optimize_pdf(pdfBuffer);
34
+ }
35
+ ```
36
+
37
+ ## API
38
+
39
+ - `init()` - Initialize the WASM module (returns Promise)
40
+ - `merge_pdfs(a, b)` - Merge two PDFs into one
41
+ - `split_pdf(input, pages)` - Extract specific pages from a PDF
42
+ - `get_page_count(input)` - Get the number of pages
43
+ - `get_pdf_info(input)` - Get PDF metadata as an object
44
+ - `optimize_pdf(input)` - Optimize a PDF by recompressing
45
+
46
+ ## Benchmarks
47
+
48
+ ```
49
+ PDF Engine Benchmarks (20 iterations, avg ms)
50
+ ========================================================
51
+ get_page_count (50 pages): 0.598 ms
52
+ split_pdf (8 pages): 5.259 ms
53
+ merge_pdfs (2 PDFs): 0.995 ms
54
+ optimize_pdf (50 pages): 0.903 ms
55
+ get_pdf_info (50 pages): 0.636 ms
56
+ ```
57
+
58
+ Run 2026-08-01 (v1.0.41); full stdout at evidence/benchmark-v1.0.41.log; raw results at benchmark-results.txt.
59
+
60
+ ## License
61
+
62
+ MIT
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "pdf_engine",
3
+ "type": "module",
4
+ "version": "1.0.41",
5
+ "license": "MIT",
6
+ "files": [
7
+ "pdf_engine_bg.wasm",
8
+ "pdf_engine.js",
9
+ "pdf_engine_bg.js",
10
+ "pdf_engine.d.ts"
11
+ ],
12
+ "main": "pdf_engine.js",
13
+ "types": "pdf_engine.d.ts",
14
+ "sideEffects": [
15
+ "./pdf_engine.js",
16
+ "./snippets/*"
17
+ ]
18
+ }
@@ -0,0 +1,16 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function get_page_count(input: Uint8Array): number;
5
+
6
+ export function get_pdf_info(input: Uint8Array): any;
7
+
8
+ export function init(): Promise<any>;
9
+
10
+ export function merge_pdfs(a: Uint8Array, b: Uint8Array): Uint8Array;
11
+
12
+ export function merge_pdfs_vec(docs: Array<any>): Uint8Array;
13
+
14
+ export function optimize_pdf(input: Uint8Array): Uint8Array;
15
+
16
+ export function split_pdf(input: Uint8Array, pages: Array<any>): Array<any>;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./pdf_engine.d.ts" */
2
+ import * as wasm from "./pdf_engine_bg.wasm";
3
+ import { __wbg_set_wasm } from "./pdf_engine_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ get_page_count, get_pdf_info, init, merge_pdfs, merge_pdfs_vec, optimize_pdf, split_pdf
9
+ } from "./pdf_engine_bg.js";
@@ -0,0 +1,238 @@
1
+ /**
2
+ * @param {Uint8Array} input
3
+ * @returns {number}
4
+ */
5
+ export function get_page_count(input) {
6
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
7
+ const len0 = WASM_VECTOR_LEN;
8
+ const ret = wasm.get_page_count(ptr0, len0);
9
+ if (ret[2]) {
10
+ throw takeFromExternrefTable0(ret[1]);
11
+ }
12
+ return ret[0] >>> 0;
13
+ }
14
+
15
+ /**
16
+ * @param {Uint8Array} input
17
+ * @returns {any}
18
+ */
19
+ export function get_pdf_info(input) {
20
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
21
+ const len0 = WASM_VECTOR_LEN;
22
+ const ret = wasm.get_pdf_info(ptr0, len0);
23
+ if (ret[2]) {
24
+ throw takeFromExternrefTable0(ret[1]);
25
+ }
26
+ return takeFromExternrefTable0(ret[0]);
27
+ }
28
+
29
+ /**
30
+ * @returns {Promise<any>}
31
+ */
32
+ export function init() {
33
+ const ret = wasm.init();
34
+ return ret;
35
+ }
36
+
37
+ /**
38
+ * @param {Uint8Array} a
39
+ * @param {Uint8Array} b
40
+ * @returns {Uint8Array}
41
+ */
42
+ export function merge_pdfs(a, b) {
43
+ const ptr0 = passArray8ToWasm0(a, wasm.__wbindgen_malloc);
44
+ const len0 = WASM_VECTOR_LEN;
45
+ const ptr1 = passArray8ToWasm0(b, wasm.__wbindgen_malloc);
46
+ const len1 = WASM_VECTOR_LEN;
47
+ const ret = wasm.merge_pdfs(ptr0, len0, ptr1, len1);
48
+ if (ret[3]) {
49
+ throw takeFromExternrefTable0(ret[2]);
50
+ }
51
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
52
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
53
+ return v3;
54
+ }
55
+
56
+ /**
57
+ * @param {Array<any>} docs
58
+ * @returns {Uint8Array}
59
+ */
60
+ export function merge_pdfs_vec(docs) {
61
+ const ret = wasm.merge_pdfs_vec(docs);
62
+ if (ret[3]) {
63
+ throw takeFromExternrefTable0(ret[2]);
64
+ }
65
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
66
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
67
+ return v1;
68
+ }
69
+
70
+ /**
71
+ * @param {Uint8Array} input
72
+ * @returns {Uint8Array}
73
+ */
74
+ export function optimize_pdf(input) {
75
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
76
+ const len0 = WASM_VECTOR_LEN;
77
+ const ret = wasm.optimize_pdf(ptr0, len0);
78
+ if (ret[3]) {
79
+ throw takeFromExternrefTable0(ret[2]);
80
+ }
81
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
82
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
83
+ return v2;
84
+ }
85
+
86
+ /**
87
+ * @param {Uint8Array} input
88
+ * @param {Array<any>} pages
89
+ * @returns {Array<any>}
90
+ */
91
+ export function split_pdf(input, pages) {
92
+ const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
93
+ const len0 = WASM_VECTOR_LEN;
94
+ const ret = wasm.split_pdf(ptr0, len0, pages);
95
+ if (ret[2]) {
96
+ throw takeFromExternrefTable0(ret[1]);
97
+ }
98
+ return takeFromExternrefTable0(ret[0]);
99
+ }
100
+ export function __wbg_Error_92b29b0548f8b746(arg0, arg1) {
101
+ const ret = Error(getStringFromWasm0(arg0, arg1));
102
+ return ret;
103
+ }
104
+ export function __wbg___wbindgen_number_get_394265ed1e1b84ee(arg0, arg1) {
105
+ const obj = arg1;
106
+ const ret = typeof(obj) === 'number' ? obj : undefined;
107
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
108
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
109
+ }
110
+ export function __wbg___wbindgen_throw_344f42d3211c4765(arg0, arg1) {
111
+ throw new Error(getStringFromWasm0(arg0, arg1));
112
+ }
113
+ export function __wbg_get_507a50627bffa49b(arg0, arg1) {
114
+ const ret = arg0[arg1 >>> 0];
115
+ return ret;
116
+ }
117
+ export function __wbg_instanceof_Uint8Array_309b927aaf7a3fc7(arg0) {
118
+ let result;
119
+ try {
120
+ result = arg0 instanceof Uint8Array;
121
+ } catch (_) {
122
+ result = false;
123
+ }
124
+ const ret = result;
125
+ return ret;
126
+ }
127
+ export function __wbg_length_1f0964f4a5e2c6d8(arg0) {
128
+ const ret = arg0.length;
129
+ return ret;
130
+ }
131
+ export function __wbg_length_370319915dc99107(arg0) {
132
+ const ret = arg0.length;
133
+ return ret;
134
+ }
135
+ export function __wbg_new_32b398fb48b6d94a() {
136
+ const ret = new Array();
137
+ return ret;
138
+ }
139
+ export function __wbg_new_7796ffc7ed656783() {
140
+ const ret = new Map();
141
+ return ret;
142
+ }
143
+ export function __wbg_new_from_slice_77cdfb7977362f3c(arg0, arg1) {
144
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
145
+ return ret;
146
+ }
147
+ export function __wbg_prototypesetcall_4770620bbe4688a0(arg0, arg1, arg2) {
148
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
149
+ }
150
+ export function __wbg_push_d2ae3af0c1217ae6(arg0, arg1) {
151
+ const ret = arg0.push(arg1);
152
+ return ret;
153
+ }
154
+ export function __wbg_resolve_2191a4dfe481c25b(arg0) {
155
+ const ret = Promise.resolve(arg0);
156
+ return ret;
157
+ }
158
+ export function __wbg_set_575dd786d51585f8(arg0, arg1, arg2) {
159
+ const ret = arg0.set(arg1, arg2);
160
+ return ret;
161
+ }
162
+ export function __wbindgen_cast_0000000000000001(arg0, arg1) {
163
+ // Cast intrinsic for `Ref(String) -> Externref`.
164
+ const ret = getStringFromWasm0(arg0, arg1);
165
+ return ret;
166
+ }
167
+ export function __wbindgen_init_externref_table() {
168
+ const table = wasm.__wbindgen_externrefs;
169
+ const offset = table.grow(4);
170
+ table.set(0, undefined);
171
+ table.set(offset + 0, undefined);
172
+ table.set(offset + 1, null);
173
+ table.set(offset + 2, true);
174
+ table.set(offset + 3, false);
175
+ }
176
+ function getArrayU8FromWasm0(ptr, len) {
177
+ ptr = ptr >>> 0;
178
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
179
+ }
180
+
181
+ let cachedDataViewMemory0 = null;
182
+ function getDataViewMemory0() {
183
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
184
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
185
+ }
186
+ return cachedDataViewMemory0;
187
+ }
188
+
189
+ function getStringFromWasm0(ptr, len) {
190
+ return decodeText(ptr >>> 0, len);
191
+ }
192
+
193
+ let cachedUint8ArrayMemory0 = null;
194
+ function getUint8ArrayMemory0() {
195
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
196
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
197
+ }
198
+ return cachedUint8ArrayMemory0;
199
+ }
200
+
201
+ function isLikeNone(x) {
202
+ return x === undefined || x === null;
203
+ }
204
+
205
+ function passArray8ToWasm0(arg, malloc) {
206
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
207
+ getUint8ArrayMemory0().set(arg, ptr / 1);
208
+ WASM_VECTOR_LEN = arg.length;
209
+ return ptr;
210
+ }
211
+
212
+ function takeFromExternrefTable0(idx) {
213
+ const value = wasm.__wbindgen_externrefs.get(idx);
214
+ wasm.__externref_table_dealloc(idx);
215
+ return value;
216
+ }
217
+
218
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
219
+ cachedTextDecoder.decode();
220
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
221
+ let numBytesDecoded = 0;
222
+ function decodeText(ptr, len) {
223
+ numBytesDecoded += len;
224
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
225
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
226
+ cachedTextDecoder.decode();
227
+ numBytesDecoded = len;
228
+ }
229
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
230
+ }
231
+
232
+ let WASM_VECTOR_LEN = 0;
233
+
234
+
235
+ let wasm;
236
+ export function __wbg_set_wasm(val) {
237
+ wasm = val;
238
+ }
Binary file
@@ -0,0 +1,15 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const get_page_count: (a: number, b: number) => [number, number, number];
5
+ export const get_pdf_info: (a: number, b: number) => [number, number, number];
6
+ export const init: () => any;
7
+ export const merge_pdfs: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
+ export const merge_pdfs_vec: (a: any) => [number, number, number, number];
9
+ export const optimize_pdf: (a: number, b: number) => [number, number, number, number];
10
+ export const split_pdf: (a: number, b: number, c: any) => [number, number, number];
11
+ export const __wbindgen_externrefs: WebAssembly.Table;
12
+ export const __wbindgen_malloc: (a: number, b: number) => number;
13
+ export const __externref_table_dealloc: (a: number) => void;
14
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
15
+ export const __wbindgen_start: () => void;