@jackgreen2018/pdf-engine 1.0.1
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 +60 -0
- package/index.d.ts +6 -0
- package/package.json +32 -0
package/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/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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.666 ms
|
|
52
|
+
split_pdf (8 pages): 1.360 ms
|
|
53
|
+
merge_pdfs (2 PDFs): 1.133 ms
|
|
54
|
+
optimize_pdf (50 pages): 0.895 ms
|
|
55
|
+
get_pdf_info (50 pages): 0.722 ms
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export default function init(): Promise<void>;
|
|
2
|
+
export function merge_pdfs(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
3
|
+
export function split_pdf(input: Uint8Array, pages: number[]): Uint8Array;
|
|
4
|
+
export function get_page_count(input: Uint8Array): number;
|
|
5
|
+
export function get_pdf_info(input: Uint8Array): object;
|
|
6
|
+
export function optimize_pdf(input: Uint8Array): Uint8Array;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jackgreen2018/pdf-engine",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Rust/WASM PDF library for merge, split, optimize and info operations",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/jackgreen2018/pdf-engine.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "pkg/pdf_engine.js",
|
|
11
|
+
"types": "index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"pkg/",
|
|
14
|
+
"index.d.ts",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"pdf",
|
|
20
|
+
"wasm",
|
|
21
|
+
"rust",
|
|
22
|
+
"merge",
|
|
23
|
+
"split",
|
|
24
|
+
"optimize"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "wasm-pack build --target bundler --release"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"pdf-lib": "^1.17.1"
|
|
31
|
+
}
|
|
32
|
+
}
|