@formepdf/core 0.10.0 → 0.10.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/dist/browser.d.ts +3 -6
- package/dist/browser.js +13 -128
- package/dist/shared/browserHelpers.d.ts +19 -0
- package/dist/shared/browserHelpers.js +128 -0
- package/dist/worker.d.ts +68 -0
- package/dist/worker.js +158 -0
- package/package.json +26 -12
- package/pkg-node/LICENSE +21 -0
- package/pkg-node/README.md +84 -0
- package/pkg-node/forme.d.ts +39 -0
- package/pkg-node/forme.js +394 -0
- package/pkg-node/forme_bg.wasm +0 -0
- package/pkg-node/forme_bg.wasm.d.ts +21 -0
- package/pkg-node/package.json +25 -0
- package/pkg-web/LICENSE +21 -0
- package/pkg-web/README.md +84 -0
- package/pkg-web/forme.d.ts +85 -0
- package/pkg-web/forme.js +479 -0
- package/pkg-web/forme_bg.wasm +0 -0
- package/pkg-web/forme_bg.wasm.d.ts +21 -0
- package/pkg-web/package.json +29 -0
- package/scripts/assert-tarball.sh +62 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# forme-pdf
|
|
2
|
+
|
|
3
|
+
A page-native PDF rendering engine written in Rust. Layout happens **into** pages, not onto an infinite canvas that gets sliced afterward — so page breaks, table headers, and flex layout all work correctly across pages.
|
|
4
|
+
|
|
5
|
+
`cargo add forme-pdf` installs the crate. The library name is `forme`:
|
|
6
|
+
|
|
7
|
+
```rust
|
|
8
|
+
use forme::{render_json, Document, FormeError};
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Page-native layout** — flexbox, tables, and text reflow with real page boundary awareness
|
|
14
|
+
- **CSS-like styling** — flexbox (`row`/`column`, `wrap`, `grow`/`shrink`), CSS Grid, absolute positioning
|
|
15
|
+
- **Text** — OpenType shaping, Knuth-Plass line breaking, hyphenation (35+ languages), BiDi, per-character font fallback
|
|
16
|
+
- **Tables** — automatic header repetition on page breaks, column spans
|
|
17
|
+
- **Images** — JPEG, PNG, WebP (embedded or data URI)
|
|
18
|
+
- **SVG** — inline SVG rendering (rect, circle, line, path, arc)
|
|
19
|
+
- **Charts** — BarChart, LineChart, PieChart, AreaChart, DotPlot (engine-native, no JS)
|
|
20
|
+
- **QR codes & barcodes** — vector rendering (Code128, Code39, EAN13, EAN8, Codabar)
|
|
21
|
+
- **Canvas** — arbitrary vector drawing via a Canvas-like API
|
|
22
|
+
- **Watermarks** — rotated text behind page content
|
|
23
|
+
- **AcroForms** — fillable PDF forms (TextField, Checkbox, Dropdown, RadioButton) with form flattening
|
|
24
|
+
- **PDF/UA-1** — accessibility compliance with structure tree, tab order, role map, artifact tagging
|
|
25
|
+
- **PDF/A** — archival compliance (PDF/A-2b, PDF/A-2a) with full font embedding and XMP metadata
|
|
26
|
+
- **Digital signatures** — PKCS#7 detached signatures with X.509 certificates
|
|
27
|
+
- **Templates** — expression language for dynamic documents (`$ref`, `$each`, `$if`)
|
|
28
|
+
- **WASM** — compiles to WebAssembly for browser and serverless use
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```rust
|
|
33
|
+
use forme::{render_json, FormeError};
|
|
34
|
+
|
|
35
|
+
fn main() -> Result<(), FormeError> {
|
|
36
|
+
let json = r#"{
|
|
37
|
+
"pages": [{ "size": "A4" }],
|
|
38
|
+
"children": [{
|
|
39
|
+
"kind": "text",
|
|
40
|
+
"content": "Hello from Forme!",
|
|
41
|
+
"style": { "fontSize": 24, "margin": { "top": 72, "left": 72 } }
|
|
42
|
+
}]
|
|
43
|
+
}"#;
|
|
44
|
+
|
|
45
|
+
let pdf_bytes = render_json(json)?;
|
|
46
|
+
std::fs::write("hello.pdf", pdf_bytes).unwrap();
|
|
47
|
+
Ok(())
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### Rendering
|
|
54
|
+
|
|
55
|
+
| Function | Description |
|
|
56
|
+
|----------|-------------|
|
|
57
|
+
| `render(&Document)` | Render a document struct to PDF bytes |
|
|
58
|
+
| `render_json(&str)` | Parse JSON and render to PDF bytes |
|
|
59
|
+
| `render_with_layout(&Document)` | Render and return PDF bytes + layout metadata |
|
|
60
|
+
| `render_json_with_layout(&str)` | Parse JSON, render, and return PDF bytes + layout metadata |
|
|
61
|
+
| `render_template(&str, &str)` | Evaluate a template with data, then render |
|
|
62
|
+
| `render_template_with_layout(&str, &str)` | Evaluate a template with data, render, and return PDF bytes + layout metadata |
|
|
63
|
+
|
|
64
|
+
### PDF Operations
|
|
65
|
+
|
|
66
|
+
| Function | Description |
|
|
67
|
+
|----------|-------------|
|
|
68
|
+
| `merge_pdfs(&[&[u8]])` | Combine multiple PDFs into one |
|
|
69
|
+
| `certify_pdf(&[u8], &str, &str, ...)` | Apply a PKCS#7 digital signature to an existing PDF |
|
|
70
|
+
| `redact_pdf(&[u8], &[RedactionRegion])` | Redact regions from a PDF (removes underlying text) |
|
|
71
|
+
| `redact_text(&[u8], &[TextSearchRedaction])` | Find text by pattern and redact matching regions |
|
|
72
|
+
| `find_text_regions(&[u8], &[TextSearchPattern])` | Find text regions in a PDF without redacting |
|
|
73
|
+
|
|
74
|
+
All functions return `Result<Vec<u8>, FormeError>` (or a tuple with `LayoutInfo` for the `_with_layout` variants).
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
- [Full docs](https://docs.formepdf.com) — component reference, styling guide, examples
|
|
79
|
+
- [API reference](https://docs.rs/forme-pdf) — Rust API docs
|
|
80
|
+
- [GitHub](https://github.com/formepdf/forme) — source, issues, JSX/TypeScript packages
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Certify PDF bytes with an X.509 certificate (PKCS#7 detached signature).
|
|
6
|
+
*/
|
|
7
|
+
export function certify_pdf(pdf_bytes: Uint8Array, config_json: string): Uint8Array;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Find text regions matching patterns in a PDF.
|
|
11
|
+
* Returns JSON string of Vec<RedactionRegion>.
|
|
12
|
+
*/
|
|
13
|
+
export function find_text_regions(pdf_bytes: Uint8Array, patterns_json: string): string;
|
|
14
|
+
|
|
15
|
+
export function init_panic_hook(): void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Merge multiple PDFs into a single document.
|
|
19
|
+
* Accepts a JSON array of base64-encoded PDF strings.
|
|
20
|
+
*/
|
|
21
|
+
export function merge_pdfs(pdfs_json: string): Uint8Array;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Redact regions of a PDF by overlaying opaque rectangles.
|
|
25
|
+
*/
|
|
26
|
+
export function redact_pdf(pdf_bytes: Uint8Array, redactions_json: string): Uint8Array;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Redact text matching patterns from a PDF.
|
|
30
|
+
*/
|
|
31
|
+
export function redact_text(pdf_bytes: Uint8Array, patterns_json: string): Uint8Array;
|
|
32
|
+
|
|
33
|
+
export function render_pdf(json: string): Uint8Array;
|
|
34
|
+
|
|
35
|
+
export function render_pdf_with_layout(json: string): any;
|
|
36
|
+
|
|
37
|
+
export function render_template_pdf(template_json: string, data_json: string): Uint8Array;
|
|
38
|
+
|
|
39
|
+
export function render_template_pdf_with_layout(template_json: string, data_json: string): any;
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/* @ts-self-types="./forme.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Certify PDF bytes with an X.509 certificate (PKCS#7 detached signature).
|
|
5
|
+
* @param {Uint8Array} pdf_bytes
|
|
6
|
+
* @param {string} config_json
|
|
7
|
+
* @returns {Uint8Array}
|
|
8
|
+
*/
|
|
9
|
+
function certify_pdf(pdf_bytes, config_json) {
|
|
10
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
11
|
+
const len0 = WASM_VECTOR_LEN;
|
|
12
|
+
const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
13
|
+
const len1 = WASM_VECTOR_LEN;
|
|
14
|
+
const ret = wasm.certify_pdf(ptr0, len0, ptr1, len1);
|
|
15
|
+
if (ret[3]) {
|
|
16
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
17
|
+
}
|
|
18
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
19
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
20
|
+
return v3;
|
|
21
|
+
}
|
|
22
|
+
exports.certify_pdf = certify_pdf;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Find text regions matching patterns in a PDF.
|
|
26
|
+
* Returns JSON string of Vec<RedactionRegion>.
|
|
27
|
+
* @param {Uint8Array} pdf_bytes
|
|
28
|
+
* @param {string} patterns_json
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
function find_text_regions(pdf_bytes, patterns_json) {
|
|
32
|
+
let deferred4_0;
|
|
33
|
+
let deferred4_1;
|
|
34
|
+
try {
|
|
35
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
36
|
+
const len0 = WASM_VECTOR_LEN;
|
|
37
|
+
const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
38
|
+
const len1 = WASM_VECTOR_LEN;
|
|
39
|
+
const ret = wasm.find_text_regions(ptr0, len0, ptr1, len1);
|
|
40
|
+
var ptr3 = ret[0];
|
|
41
|
+
var len3 = ret[1];
|
|
42
|
+
if (ret[3]) {
|
|
43
|
+
ptr3 = 0; len3 = 0;
|
|
44
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
45
|
+
}
|
|
46
|
+
deferred4_0 = ptr3;
|
|
47
|
+
deferred4_1 = len3;
|
|
48
|
+
return getStringFromWasm0(ptr3, len3);
|
|
49
|
+
} finally {
|
|
50
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.find_text_regions = find_text_regions;
|
|
54
|
+
|
|
55
|
+
function init_panic_hook() {
|
|
56
|
+
wasm.init_panic_hook();
|
|
57
|
+
}
|
|
58
|
+
exports.init_panic_hook = init_panic_hook;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Merge multiple PDFs into a single document.
|
|
62
|
+
* Accepts a JSON array of base64-encoded PDF strings.
|
|
63
|
+
* @param {string} pdfs_json
|
|
64
|
+
* @returns {Uint8Array}
|
|
65
|
+
*/
|
|
66
|
+
function merge_pdfs(pdfs_json) {
|
|
67
|
+
const ptr0 = passStringToWasm0(pdfs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
68
|
+
const len0 = WASM_VECTOR_LEN;
|
|
69
|
+
const ret = wasm.merge_pdfs(ptr0, len0);
|
|
70
|
+
if (ret[3]) {
|
|
71
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
72
|
+
}
|
|
73
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
74
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
75
|
+
return v2;
|
|
76
|
+
}
|
|
77
|
+
exports.merge_pdfs = merge_pdfs;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Redact regions of a PDF by overlaying opaque rectangles.
|
|
81
|
+
* @param {Uint8Array} pdf_bytes
|
|
82
|
+
* @param {string} redactions_json
|
|
83
|
+
* @returns {Uint8Array}
|
|
84
|
+
*/
|
|
85
|
+
function redact_pdf(pdf_bytes, redactions_json) {
|
|
86
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
87
|
+
const len0 = WASM_VECTOR_LEN;
|
|
88
|
+
const ptr1 = passStringToWasm0(redactions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
89
|
+
const len1 = WASM_VECTOR_LEN;
|
|
90
|
+
const ret = wasm.redact_pdf(ptr0, len0, ptr1, len1);
|
|
91
|
+
if (ret[3]) {
|
|
92
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
93
|
+
}
|
|
94
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
95
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
96
|
+
return v3;
|
|
97
|
+
}
|
|
98
|
+
exports.redact_pdf = redact_pdf;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Redact text matching patterns from a PDF.
|
|
102
|
+
* @param {Uint8Array} pdf_bytes
|
|
103
|
+
* @param {string} patterns_json
|
|
104
|
+
* @returns {Uint8Array}
|
|
105
|
+
*/
|
|
106
|
+
function redact_text(pdf_bytes, patterns_json) {
|
|
107
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
108
|
+
const len0 = WASM_VECTOR_LEN;
|
|
109
|
+
const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
110
|
+
const len1 = WASM_VECTOR_LEN;
|
|
111
|
+
const ret = wasm.redact_text(ptr0, len0, ptr1, len1);
|
|
112
|
+
if (ret[3]) {
|
|
113
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
114
|
+
}
|
|
115
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
116
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
117
|
+
return v3;
|
|
118
|
+
}
|
|
119
|
+
exports.redact_text = redact_text;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {string} json
|
|
123
|
+
* @returns {Uint8Array}
|
|
124
|
+
*/
|
|
125
|
+
function render_pdf(json) {
|
|
126
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
127
|
+
const len0 = WASM_VECTOR_LEN;
|
|
128
|
+
const ret = wasm.render_pdf(ptr0, len0);
|
|
129
|
+
if (ret[3]) {
|
|
130
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
131
|
+
}
|
|
132
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
133
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
134
|
+
return v2;
|
|
135
|
+
}
|
|
136
|
+
exports.render_pdf = render_pdf;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {string} json
|
|
140
|
+
* @returns {any}
|
|
141
|
+
*/
|
|
142
|
+
function render_pdf_with_layout(json) {
|
|
143
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
144
|
+
const len0 = WASM_VECTOR_LEN;
|
|
145
|
+
const ret = wasm.render_pdf_with_layout(ptr0, len0);
|
|
146
|
+
if (ret[2]) {
|
|
147
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
148
|
+
}
|
|
149
|
+
return takeFromExternrefTable0(ret[0]);
|
|
150
|
+
}
|
|
151
|
+
exports.render_pdf_with_layout = render_pdf_with_layout;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param {string} template_json
|
|
155
|
+
* @param {string} data_json
|
|
156
|
+
* @returns {Uint8Array}
|
|
157
|
+
*/
|
|
158
|
+
function render_template_pdf(template_json, data_json) {
|
|
159
|
+
const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
160
|
+
const len0 = WASM_VECTOR_LEN;
|
|
161
|
+
const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
162
|
+
const len1 = WASM_VECTOR_LEN;
|
|
163
|
+
const ret = wasm.render_template_pdf(ptr0, len0, ptr1, len1);
|
|
164
|
+
if (ret[3]) {
|
|
165
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
166
|
+
}
|
|
167
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
168
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
169
|
+
return v3;
|
|
170
|
+
}
|
|
171
|
+
exports.render_template_pdf = render_template_pdf;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @param {string} template_json
|
|
175
|
+
* @param {string} data_json
|
|
176
|
+
* @returns {any}
|
|
177
|
+
*/
|
|
178
|
+
function render_template_pdf_with_layout(template_json, data_json) {
|
|
179
|
+
const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
180
|
+
const len0 = WASM_VECTOR_LEN;
|
|
181
|
+
const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
182
|
+
const len1 = WASM_VECTOR_LEN;
|
|
183
|
+
const ret = wasm.render_template_pdf_with_layout(ptr0, len0, ptr1, len1);
|
|
184
|
+
if (ret[2]) {
|
|
185
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
186
|
+
}
|
|
187
|
+
return takeFromExternrefTable0(ret[0]);
|
|
188
|
+
}
|
|
189
|
+
exports.render_template_pdf_with_layout = render_template_pdf_with_layout;
|
|
190
|
+
|
|
191
|
+
function __wbg_get_imports() {
|
|
192
|
+
const import0 = {
|
|
193
|
+
__proto__: null,
|
|
194
|
+
__wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
|
|
195
|
+
const ret = String(arg1);
|
|
196
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
197
|
+
const len1 = WASM_VECTOR_LEN;
|
|
198
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
199
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
200
|
+
},
|
|
201
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
202
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
203
|
+
},
|
|
204
|
+
__wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
|
|
205
|
+
let deferred0_0;
|
|
206
|
+
let deferred0_1;
|
|
207
|
+
try {
|
|
208
|
+
deferred0_0 = arg0;
|
|
209
|
+
deferred0_1 = arg1;
|
|
210
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
211
|
+
} finally {
|
|
212
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
__wbg_new_361308b2356cecd0: function() {
|
|
216
|
+
const ret = new Object();
|
|
217
|
+
return ret;
|
|
218
|
+
},
|
|
219
|
+
__wbg_new_3eb36ae241fe6f44: function() {
|
|
220
|
+
const ret = new Array();
|
|
221
|
+
return ret;
|
|
222
|
+
},
|
|
223
|
+
__wbg_new_8a6f238a6ece86ea: function() {
|
|
224
|
+
const ret = new Error();
|
|
225
|
+
return ret;
|
|
226
|
+
},
|
|
227
|
+
__wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
|
|
228
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
229
|
+
return ret;
|
|
230
|
+
},
|
|
231
|
+
__wbg_now_a3af9a2f4bbaa4d1: function() {
|
|
232
|
+
const ret = Date.now();
|
|
233
|
+
return ret;
|
|
234
|
+
},
|
|
235
|
+
__wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
|
|
236
|
+
arg0[arg1] = arg2;
|
|
237
|
+
},
|
|
238
|
+
__wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
|
|
239
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
240
|
+
return ret;
|
|
241
|
+
}, arguments); },
|
|
242
|
+
__wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
|
|
243
|
+
arg0[arg1 >>> 0] = arg2;
|
|
244
|
+
},
|
|
245
|
+
__wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
|
|
246
|
+
const ret = arg1.stack;
|
|
247
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
248
|
+
const len1 = WASM_VECTOR_LEN;
|
|
249
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
250
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
251
|
+
},
|
|
252
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
253
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
254
|
+
const ret = arg0;
|
|
255
|
+
return ret;
|
|
256
|
+
},
|
|
257
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
258
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
259
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
260
|
+
return ret;
|
|
261
|
+
},
|
|
262
|
+
__wbindgen_init_externref_table: function() {
|
|
263
|
+
const table = wasm.__wbindgen_externrefs;
|
|
264
|
+
const offset = table.grow(4);
|
|
265
|
+
table.set(0, undefined);
|
|
266
|
+
table.set(offset + 0, undefined);
|
|
267
|
+
table.set(offset + 1, null);
|
|
268
|
+
table.set(offset + 2, true);
|
|
269
|
+
table.set(offset + 3, false);
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
return {
|
|
273
|
+
__proto__: null,
|
|
274
|
+
"./forme_bg.js": import0,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function addToExternrefTable0(obj) {
|
|
279
|
+
const idx = wasm.__externref_table_alloc();
|
|
280
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
281
|
+
return idx;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
285
|
+
ptr = ptr >>> 0;
|
|
286
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
let cachedDataViewMemory0 = null;
|
|
290
|
+
function getDataViewMemory0() {
|
|
291
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
292
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
293
|
+
}
|
|
294
|
+
return cachedDataViewMemory0;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function getStringFromWasm0(ptr, len) {
|
|
298
|
+
ptr = ptr >>> 0;
|
|
299
|
+
return decodeText(ptr, len);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
let cachedUint8ArrayMemory0 = null;
|
|
303
|
+
function getUint8ArrayMemory0() {
|
|
304
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
305
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
306
|
+
}
|
|
307
|
+
return cachedUint8ArrayMemory0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function handleError(f, args) {
|
|
311
|
+
try {
|
|
312
|
+
return f.apply(this, args);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
const idx = addToExternrefTable0(e);
|
|
315
|
+
wasm.__wbindgen_exn_store(idx);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
320
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
321
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
322
|
+
WASM_VECTOR_LEN = arg.length;
|
|
323
|
+
return ptr;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
327
|
+
if (realloc === undefined) {
|
|
328
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
329
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
330
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
331
|
+
WASM_VECTOR_LEN = buf.length;
|
|
332
|
+
return ptr;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
let len = arg.length;
|
|
336
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
337
|
+
|
|
338
|
+
const mem = getUint8ArrayMemory0();
|
|
339
|
+
|
|
340
|
+
let offset = 0;
|
|
341
|
+
|
|
342
|
+
for (; offset < len; offset++) {
|
|
343
|
+
const code = arg.charCodeAt(offset);
|
|
344
|
+
if (code > 0x7F) break;
|
|
345
|
+
mem[ptr + offset] = code;
|
|
346
|
+
}
|
|
347
|
+
if (offset !== len) {
|
|
348
|
+
if (offset !== 0) {
|
|
349
|
+
arg = arg.slice(offset);
|
|
350
|
+
}
|
|
351
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
352
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
353
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
354
|
+
|
|
355
|
+
offset += ret.written;
|
|
356
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
WASM_VECTOR_LEN = offset;
|
|
360
|
+
return ptr;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function takeFromExternrefTable0(idx) {
|
|
364
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
365
|
+
wasm.__externref_table_dealloc(idx);
|
|
366
|
+
return value;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
370
|
+
cachedTextDecoder.decode();
|
|
371
|
+
function decodeText(ptr, len) {
|
|
372
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const cachedTextEncoder = new TextEncoder();
|
|
376
|
+
|
|
377
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
378
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
379
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
380
|
+
view.set(buf);
|
|
381
|
+
return {
|
|
382
|
+
read: arg.length,
|
|
383
|
+
written: buf.length
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
let WASM_VECTOR_LEN = 0;
|
|
389
|
+
|
|
390
|
+
const wasmPath = `${__dirname}/forme_bg.wasm`;
|
|
391
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
392
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
393
|
+
const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
394
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const certify_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
5
|
+
export const find_text_regions: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
6
|
+
export const merge_pdfs: (a: number, b: number) => [number, number, number, number];
|
|
7
|
+
export const redact_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
8
|
+
export const redact_text: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
9
|
+
export const render_pdf: (a: number, b: number) => [number, number, number, number];
|
|
10
|
+
export const render_pdf_with_layout: (a: number, b: number) => [number, number, number];
|
|
11
|
+
export const render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
12
|
+
export const render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
13
|
+
export const init_panic_hook: () => void;
|
|
14
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
15
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
16
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
17
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
18
|
+
export const __externref_table_alloc: () => number;
|
|
19
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
20
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
21
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "forme-pdf",
|
|
3
|
+
"description": "A page-native PDF rendering engine. Layout INTO pages, not onto an infinite canvas.",
|
|
4
|
+
"version": "0.10.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/formepdf/forme"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"forme_bg.wasm",
|
|
12
|
+
"forme.js",
|
|
13
|
+
"forme.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"main": "forme.js",
|
|
16
|
+
"homepage": "https://formepdf.com",
|
|
17
|
+
"types": "forme.d.ts",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"pdf",
|
|
20
|
+
"wasm",
|
|
21
|
+
"layout",
|
|
22
|
+
"document",
|
|
23
|
+
"report"
|
|
24
|
+
]
|
|
25
|
+
}
|
package/pkg-web/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Molitor
|
|
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.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# forme-pdf
|
|
2
|
+
|
|
3
|
+
A page-native PDF rendering engine written in Rust. Layout happens **into** pages, not onto an infinite canvas that gets sliced afterward — so page breaks, table headers, and flex layout all work correctly across pages.
|
|
4
|
+
|
|
5
|
+
`cargo add forme-pdf` installs the crate. The library name is `forme`:
|
|
6
|
+
|
|
7
|
+
```rust
|
|
8
|
+
use forme::{render_json, Document, FormeError};
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Page-native layout** — flexbox, tables, and text reflow with real page boundary awareness
|
|
14
|
+
- **CSS-like styling** — flexbox (`row`/`column`, `wrap`, `grow`/`shrink`), CSS Grid, absolute positioning
|
|
15
|
+
- **Text** — OpenType shaping, Knuth-Plass line breaking, hyphenation (35+ languages), BiDi, per-character font fallback
|
|
16
|
+
- **Tables** — automatic header repetition on page breaks, column spans
|
|
17
|
+
- **Images** — JPEG, PNG, WebP (embedded or data URI)
|
|
18
|
+
- **SVG** — inline SVG rendering (rect, circle, line, path, arc)
|
|
19
|
+
- **Charts** — BarChart, LineChart, PieChart, AreaChart, DotPlot (engine-native, no JS)
|
|
20
|
+
- **QR codes & barcodes** — vector rendering (Code128, Code39, EAN13, EAN8, Codabar)
|
|
21
|
+
- **Canvas** — arbitrary vector drawing via a Canvas-like API
|
|
22
|
+
- **Watermarks** — rotated text behind page content
|
|
23
|
+
- **AcroForms** — fillable PDF forms (TextField, Checkbox, Dropdown, RadioButton) with form flattening
|
|
24
|
+
- **PDF/UA-1** — accessibility compliance with structure tree, tab order, role map, artifact tagging
|
|
25
|
+
- **PDF/A** — archival compliance (PDF/A-2b, PDF/A-2a) with full font embedding and XMP metadata
|
|
26
|
+
- **Digital signatures** — PKCS#7 detached signatures with X.509 certificates
|
|
27
|
+
- **Templates** — expression language for dynamic documents (`$ref`, `$each`, `$if`)
|
|
28
|
+
- **WASM** — compiles to WebAssembly for browser and serverless use
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```rust
|
|
33
|
+
use forme::{render_json, FormeError};
|
|
34
|
+
|
|
35
|
+
fn main() -> Result<(), FormeError> {
|
|
36
|
+
let json = r#"{
|
|
37
|
+
"pages": [{ "size": "A4" }],
|
|
38
|
+
"children": [{
|
|
39
|
+
"kind": "text",
|
|
40
|
+
"content": "Hello from Forme!",
|
|
41
|
+
"style": { "fontSize": 24, "margin": { "top": 72, "left": 72 } }
|
|
42
|
+
}]
|
|
43
|
+
}"#;
|
|
44
|
+
|
|
45
|
+
let pdf_bytes = render_json(json)?;
|
|
46
|
+
std::fs::write("hello.pdf", pdf_bytes).unwrap();
|
|
47
|
+
Ok(())
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### Rendering
|
|
54
|
+
|
|
55
|
+
| Function | Description |
|
|
56
|
+
|----------|-------------|
|
|
57
|
+
| `render(&Document)` | Render a document struct to PDF bytes |
|
|
58
|
+
| `render_json(&str)` | Parse JSON and render to PDF bytes |
|
|
59
|
+
| `render_with_layout(&Document)` | Render and return PDF bytes + layout metadata |
|
|
60
|
+
| `render_json_with_layout(&str)` | Parse JSON, render, and return PDF bytes + layout metadata |
|
|
61
|
+
| `render_template(&str, &str)` | Evaluate a template with data, then render |
|
|
62
|
+
| `render_template_with_layout(&str, &str)` | Evaluate a template with data, render, and return PDF bytes + layout metadata |
|
|
63
|
+
|
|
64
|
+
### PDF Operations
|
|
65
|
+
|
|
66
|
+
| Function | Description |
|
|
67
|
+
|----------|-------------|
|
|
68
|
+
| `merge_pdfs(&[&[u8]])` | Combine multiple PDFs into one |
|
|
69
|
+
| `certify_pdf(&[u8], &str, &str, ...)` | Apply a PKCS#7 digital signature to an existing PDF |
|
|
70
|
+
| `redact_pdf(&[u8], &[RedactionRegion])` | Redact regions from a PDF (removes underlying text) |
|
|
71
|
+
| `redact_text(&[u8], &[TextSearchRedaction])` | Find text by pattern and redact matching regions |
|
|
72
|
+
| `find_text_regions(&[u8], &[TextSearchPattern])` | Find text regions in a PDF without redacting |
|
|
73
|
+
|
|
74
|
+
All functions return `Result<Vec<u8>, FormeError>` (or a tuple with `LayoutInfo` for the `_with_layout` variants).
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
- [Full docs](https://docs.formepdf.com) — component reference, styling guide, examples
|
|
79
|
+
- [API reference](https://docs.rs/forme-pdf) — Rust API docs
|
|
80
|
+
- [GitHub](https://github.com/formepdf/forme) — source, issues, JSX/TypeScript packages
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|