@jackgreen2018/pdf-engine 1.0.95 → 1.0.97
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 +5 -5
- package/README.md +152 -50
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +60 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/package.json +44 -26
- package/pkg/LICENSE +21 -0
- package/pkg/README.md +176 -0
- package/pkg/package.json +16 -0
- package/pkg/pdf_engine.d.ts +14 -0
- package/pkg/pdf_engine.js +9 -0
- package/pkg/pdf_engine_bg.js +220 -0
- package/pkg/pdf_engine_bg.wasm +0 -0
- package/pkg/pdf_engine_bg.wasm.d.ts +14 -0
- package/src/cli.ts +66 -0
- package/src/index.ts +62 -0
- package/src/lib.rs +294 -0
- package/index.d.ts +0 -11
- package/index.js +0 -79
- package/pkg/pdf_tool.d.ts +0 -32
- package/pkg/pdf_tool.js +0 -9
- package/pkg/pdf_tool_bg.wasm +0 -0
- package/pkg/pdf_tool_bg.wasm.d.ts +0 -15
package/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
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/pkg/pdf_tool.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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";
|
package/pkg/pdf_tool_bg.wasm
DELETED
|
Binary file
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|