@formepdf/core 0.7.13 → 0.8.0
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 +13 -0
- package/dist/browser.js +18 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +12 -0
- package/package.json +2 -2
- package/pkg/LICENSE +21 -0
- package/pkg/README.md +70 -0
- package/pkg/forme.d.ts +6 -0
- package/pkg/forme.js +27 -0
- package/pkg/forme_bg.wasm +0 -0
- package/pkg/forme_bg.wasm.d.ts +1 -0
- package/pkg/package.json +15 -2
package/dist/browser.d.ts
CHANGED
|
@@ -45,6 +45,19 @@ export declare function renderSerializedDoc(doc: Record<string, unknown>, option
|
|
|
45
45
|
export declare function renderSerializedDocWithLayout(doc: Record<string, unknown>, options?: RenderDocumentOptions): Promise<RenderWithLayoutResult>;
|
|
46
46
|
export declare function renderTemplate(templateJson: string, dataJson: string): Promise<Uint8Array>;
|
|
47
47
|
export declare function renderTemplateWithLayout(templateJson: string, dataJson: string): Promise<RenderWithLayoutResult>;
|
|
48
|
+
export declare function signPdf(pdfBytes: Uint8Array, config: {
|
|
49
|
+
certificatePem: string;
|
|
50
|
+
privateKeyPem: string;
|
|
51
|
+
reason?: string;
|
|
52
|
+
location?: string;
|
|
53
|
+
contact?: string;
|
|
54
|
+
visible?: boolean;
|
|
55
|
+
page?: number;
|
|
56
|
+
x?: number;
|
|
57
|
+
y?: number;
|
|
58
|
+
width?: number;
|
|
59
|
+
height?: number;
|
|
60
|
+
}): Promise<Uint8Array>;
|
|
48
61
|
/**
|
|
49
62
|
* Extract embedded JSON data from a Forme-generated PDF.
|
|
50
63
|
* Uses the browser-native DecompressionStream API (no node:zlib).
|
package/dist/browser.js
CHANGED
|
@@ -112,6 +112,9 @@ export async function renderDocument(element, options) {
|
|
|
112
112
|
if (options?.embedData !== undefined) {
|
|
113
113
|
doc.embeddedData = JSON.stringify(options.embedData);
|
|
114
114
|
}
|
|
115
|
+
if (options?.flattenForms) {
|
|
116
|
+
doc.flattenForms = true;
|
|
117
|
+
}
|
|
115
118
|
await Promise.all([resolveFonts(doc), resolveImages(doc)]);
|
|
116
119
|
return renderPdf(JSON.stringify(doc));
|
|
117
120
|
}
|
|
@@ -121,6 +124,9 @@ export async function renderDocumentWithLayout(element, options) {
|
|
|
121
124
|
if (options?.embedData !== undefined) {
|
|
122
125
|
doc.embeddedData = JSON.stringify(options.embedData);
|
|
123
126
|
}
|
|
127
|
+
if (options?.flattenForms) {
|
|
128
|
+
doc.flattenForms = true;
|
|
129
|
+
}
|
|
124
130
|
await Promise.all([resolveFonts(doc), resolveImages(doc)]);
|
|
125
131
|
return renderPdfWithLayout(JSON.stringify(doc));
|
|
126
132
|
}
|
|
@@ -137,6 +143,9 @@ export async function renderSerializedDoc(doc, options) {
|
|
|
137
143
|
if (options?.embedData !== undefined) {
|
|
138
144
|
doc.embeddedData = JSON.stringify(options.embedData);
|
|
139
145
|
}
|
|
146
|
+
if (options?.flattenForms) {
|
|
147
|
+
doc.flattenForms = true;
|
|
148
|
+
}
|
|
140
149
|
await Promise.all([resolveFonts(doc), resolveImages(doc)]);
|
|
141
150
|
return renderPdf(JSON.stringify(doc));
|
|
142
151
|
}
|
|
@@ -147,6 +156,9 @@ export async function renderSerializedDocWithLayout(doc, options) {
|
|
|
147
156
|
if (options?.embedData !== undefined) {
|
|
148
157
|
doc.embeddedData = JSON.stringify(options.embedData);
|
|
149
158
|
}
|
|
159
|
+
if (options?.flattenForms) {
|
|
160
|
+
doc.flattenForms = true;
|
|
161
|
+
}
|
|
150
162
|
await Promise.all([resolveFonts(doc), resolveImages(doc)]);
|
|
151
163
|
return renderPdfWithLayout(JSON.stringify(doc));
|
|
152
164
|
}
|
|
@@ -160,6 +172,12 @@ export async function renderTemplateWithLayout(templateJson, dataJson) {
|
|
|
160
172
|
const result = wasmRenderTemplatePdfWithLayout(templateJson, dataJson);
|
|
161
173
|
return result;
|
|
162
174
|
}
|
|
175
|
+
// ── PDF signing ──────────────────────────────────────────────────────
|
|
176
|
+
export async function signPdf(pdfBytes, config) {
|
|
177
|
+
await ensureInit();
|
|
178
|
+
const { sign_pdf } = await import('../pkg/forme.js');
|
|
179
|
+
return sign_pdf(pdfBytes, JSON.stringify(config));
|
|
180
|
+
}
|
|
163
181
|
// ── Data extraction (browser-native decompression) ──────────────────
|
|
164
182
|
/**
|
|
165
183
|
* Extract embedded JSON data from a Forme-generated PDF.
|
package/dist/index.d.ts
CHANGED
|
@@ -72,12 +72,28 @@ export interface RenderWithLayoutResult {
|
|
|
72
72
|
}
|
|
73
73
|
export declare function renderPdf(json: string): Promise<Uint8Array>;
|
|
74
74
|
export declare function renderPdfWithLayout(json: string): Promise<RenderWithLayoutResult>;
|
|
75
|
+
export interface SignatureConfig {
|
|
76
|
+
certificatePem: string;
|
|
77
|
+
privateKeyPem: string;
|
|
78
|
+
reason?: string;
|
|
79
|
+
location?: string;
|
|
80
|
+
contact?: string;
|
|
81
|
+
visible?: boolean;
|
|
82
|
+
page?: number;
|
|
83
|
+
x?: number;
|
|
84
|
+
y?: number;
|
|
85
|
+
width?: number;
|
|
86
|
+
height?: number;
|
|
87
|
+
}
|
|
75
88
|
export interface RenderDocumentOptions {
|
|
76
89
|
/** Data to embed as a hidden JSON attachment in the PDF. */
|
|
77
90
|
embedData?: unknown;
|
|
91
|
+
/** When true, form field values are rendered as static text. No interactive fields in output. */
|
|
92
|
+
flattenForms?: boolean;
|
|
78
93
|
}
|
|
79
94
|
export declare function renderDocument(element: ReactElement, options?: RenderDocumentOptions): Promise<Uint8Array>;
|
|
80
95
|
export declare function renderDocumentWithLayout(element: ReactElement, options?: RenderDocumentOptions): Promise<RenderWithLayoutResult>;
|
|
81
96
|
export declare function renderTemplate(templateJson: string, dataJson: string): Promise<Uint8Array>;
|
|
82
97
|
export declare function renderTemplateWithLayout(templateJson: string, dataJson: string): Promise<RenderWithLayoutResult>;
|
|
98
|
+
export declare function signPdf(pdfBytes: Uint8Array, config: SignatureConfig): Promise<Uint8Array>;
|
|
83
99
|
export { extractData } from './extract.js';
|
package/dist/index.js
CHANGED
|
@@ -79,6 +79,9 @@ export async function renderDocument(element, options) {
|
|
|
79
79
|
if (options?.embedData !== undefined) {
|
|
80
80
|
doc.embeddedData = JSON.stringify(options.embedData);
|
|
81
81
|
}
|
|
82
|
+
if (options?.flattenForms) {
|
|
83
|
+
doc.flattenForms = true;
|
|
84
|
+
}
|
|
82
85
|
await Promise.all([resolveFonts(doc), resolveImages(doc)]);
|
|
83
86
|
return renderPdf(JSON.stringify(doc));
|
|
84
87
|
}
|
|
@@ -88,6 +91,9 @@ export async function renderDocumentWithLayout(element, options) {
|
|
|
88
91
|
if (options?.embedData !== undefined) {
|
|
89
92
|
doc.embeddedData = JSON.stringify(options.embedData);
|
|
90
93
|
}
|
|
94
|
+
if (options?.flattenForms) {
|
|
95
|
+
doc.flattenForms = true;
|
|
96
|
+
}
|
|
91
97
|
await Promise.all([resolveFonts(doc), resolveImages(doc)]);
|
|
92
98
|
return renderPdfWithLayout(JSON.stringify(doc));
|
|
93
99
|
}
|
|
@@ -103,5 +109,11 @@ export async function renderTemplateWithLayout(templateJson, dataJson) {
|
|
|
103
109
|
const result = render_template_pdf_with_layout(templateJson, dataJson);
|
|
104
110
|
return result;
|
|
105
111
|
}
|
|
112
|
+
// ── PDF signing ──────────────────────────────────────────────────────
|
|
113
|
+
export async function signPdf(pdfBytes, config) {
|
|
114
|
+
await ensureInit();
|
|
115
|
+
const { sign_pdf } = await import('../pkg/forme.js');
|
|
116
|
+
return sign_pdf(pdfBytes, JSON.stringify(config));
|
|
117
|
+
}
|
|
106
118
|
// ── Data extraction ──────────────────────────────────────────────────
|
|
107
119
|
export { extractData } from './extract.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formepdf/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "WASM-powered PDF rendering engine for Forme",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"test": "vitest run"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@formepdf/react": "0.
|
|
51
|
+
"@formepdf/react": "0.8.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"react": "^18 || ^19"
|
package/pkg/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.
|
package/pkg/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
| Function | Description |
|
|
54
|
+
|----------|-------------|
|
|
55
|
+
| `render(&Document)` | Render a document struct to PDF bytes |
|
|
56
|
+
| `render_json(&str)` | Parse JSON and render to PDF bytes |
|
|
57
|
+
| `render_with_layout(&Document)` | Render and return layout metadata |
|
|
58
|
+
| `render_template(&str, &str)` | Evaluate a template with data, then render |
|
|
59
|
+
|
|
60
|
+
All functions return `Result<Vec<u8>, FormeError>` (or a tuple with `LayoutInfo` for the `_with_layout` variants).
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
- [Full docs](https://docs.formepdf.com) — component reference, styling guide, examples
|
|
65
|
+
- [API reference](https://docs.rs/forme-pdf) — Rust API docs
|
|
66
|
+
- [GitHub](https://github.com/formepdf/forme) — source, issues, JSX/TypeScript packages
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
package/pkg/forme.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export function render_template_pdf(template_json: string, data_json: string): U
|
|
|
9
9
|
|
|
10
10
|
export function render_template_pdf_with_layout(template_json: string, data_json: string): any;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Sign PDF bytes with an X.509 certificate (PKCS#7 detached signature).
|
|
14
|
+
*/
|
|
15
|
+
export function sign_pdf(pdf_bytes: Uint8Array, config_json: string): Uint8Array;
|
|
16
|
+
|
|
12
17
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
13
18
|
|
|
14
19
|
export interface InitOutput {
|
|
@@ -17,6 +22,7 @@ export interface InitOutput {
|
|
|
17
22
|
readonly render_pdf_with_layout: (a: number, b: number) => [number, number, number];
|
|
18
23
|
readonly render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
19
24
|
readonly render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
25
|
+
readonly sign_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
20
26
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
21
27
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
22
28
|
readonly __wbindgen_exn_store: (a: number) => void;
|
package/pkg/forme.js
CHANGED
|
@@ -66,6 +66,26 @@ export function render_template_pdf_with_layout(template_json, data_json) {
|
|
|
66
66
|
return takeFromExternrefTable0(ret[0]);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Sign PDF bytes with an X.509 certificate (PKCS#7 detached signature).
|
|
71
|
+
* @param {Uint8Array} pdf_bytes
|
|
72
|
+
* @param {string} config_json
|
|
73
|
+
* @returns {Uint8Array}
|
|
74
|
+
*/
|
|
75
|
+
export function sign_pdf(pdf_bytes, config_json) {
|
|
76
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
77
|
+
const len0 = WASM_VECTOR_LEN;
|
|
78
|
+
const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
79
|
+
const len1 = WASM_VECTOR_LEN;
|
|
80
|
+
const ret = wasm.sign_pdf(ptr0, len0, ptr1, len1);
|
|
81
|
+
if (ret[3]) {
|
|
82
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
83
|
+
}
|
|
84
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
85
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
86
|
+
return v3;
|
|
87
|
+
}
|
|
88
|
+
|
|
69
89
|
function __wbg_get_imports() {
|
|
70
90
|
const import0 = {
|
|
71
91
|
__proto__: null,
|
|
@@ -168,6 +188,13 @@ function handleError(f, args) {
|
|
|
168
188
|
}
|
|
169
189
|
}
|
|
170
190
|
|
|
191
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
192
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
193
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
194
|
+
WASM_VECTOR_LEN = arg.length;
|
|
195
|
+
return ptr;
|
|
196
|
+
}
|
|
197
|
+
|
|
171
198
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
172
199
|
if (realloc === undefined) {
|
|
173
200
|
const buf = cachedTextEncoder.encode(arg);
|
package/pkg/forme_bg.wasm
CHANGED
|
Binary file
|
package/pkg/forme_bg.wasm.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export const render_pdf: (a: number, b: number) => [number, number, number, numb
|
|
|
5
5
|
export const render_pdf_with_layout: (a: number, b: number) => [number, number, number];
|
|
6
6
|
export const render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
7
7
|
export const render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
8
|
+
export const sign_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
8
9
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
9
10
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
10
11
|
export const __wbindgen_exn_store: (a: number) => void;
|
package/pkg/package.json
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "forme",
|
|
2
|
+
"name": "forme-pdf",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "A page-native PDF rendering engine. Layout INTO pages, not onto an infinite canvas.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.8.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/formepdf/forme"
|
|
10
|
+
},
|
|
6
11
|
"files": [
|
|
7
12
|
"forme_bg.wasm",
|
|
8
13
|
"forme.js",
|
|
9
14
|
"forme.d.ts"
|
|
10
15
|
],
|
|
11
16
|
"main": "forme.js",
|
|
17
|
+
"homepage": "https://formepdf.com",
|
|
12
18
|
"types": "forme.d.ts",
|
|
13
19
|
"sideEffects": [
|
|
14
20
|
"./snippets/*"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"pdf",
|
|
24
|
+
"wasm",
|
|
25
|
+
"layout",
|
|
26
|
+
"document",
|
|
27
|
+
"report"
|
|
15
28
|
]
|
|
16
29
|
}
|