@formepdf/core 0.8.3 → 0.9.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 +27 -3
- package/dist/browser.js +49 -4
- package/dist/index.d.ts +52 -2
- package/dist/index.js +47 -4
- package/package.json +2 -2
- package/pkg/README.md +15 -1
- package/pkg/forme.d.ts +36 -7
- package/pkg/forme.js +138 -20
- package/pkg/forme_bg.wasm +0 -0
- package/pkg/forme_bg.wasm.d.ts +7 -2
- package/pkg/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* For script-tag usage, call `initWasm()` with an explicit URL first.
|
|
11
11
|
*/
|
|
12
12
|
import type { InitInput } from '../pkg/forme.js';
|
|
13
|
-
export type { Color, EdgeValues, CornerValues, ElementStyleInfo, ElementInfo, PageInfo, LayoutInfo, RenderWithLayoutResult, RenderDocumentOptions, } from './index.js';
|
|
14
|
-
import type { RenderWithLayoutResult, RenderDocumentOptions } from './index.js';
|
|
13
|
+
export type { Color, EdgeValues, CornerValues, ElementStyleInfo, ElementInfo, PageInfo, LayoutInfo, RenderWithLayoutResult, RenderDocumentOptions, RedactionRegion, RedactionPattern, } from './index.js';
|
|
14
|
+
import type { RenderWithLayoutResult, RenderDocumentOptions, RedactionRegion, RedactionPattern } from './index.js';
|
|
15
15
|
/**
|
|
16
16
|
* Initialize the WASM module. Called automatically on first render,
|
|
17
17
|
* but you can call it early to control timing or provide a custom
|
|
@@ -45,7 +45,7 @@ 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
|
|
48
|
+
export declare function certifyPdf(pdfBytes: Uint8Array, config: {
|
|
49
49
|
certificatePem: string;
|
|
50
50
|
privateKeyPem: string;
|
|
51
51
|
reason?: string;
|
|
@@ -58,6 +58,30 @@ export declare function signPdf(pdfBytes: Uint8Array, config: {
|
|
|
58
58
|
width?: number;
|
|
59
59
|
height?: number;
|
|
60
60
|
}): Promise<Uint8Array>;
|
|
61
|
+
/** @deprecated Use certifyPdf */
|
|
62
|
+
export declare const signPdf: typeof certifyPdf;
|
|
63
|
+
export declare function redactPdf(pdfBytes: Uint8Array, regions: RedactionRegion[]): Promise<Uint8Array>;
|
|
64
|
+
/**
|
|
65
|
+
* Find text regions matching patterns in a PDF.
|
|
66
|
+
*
|
|
67
|
+
* Searches PDF content streams for literal or regex patterns and returns
|
|
68
|
+
* redaction regions (in web top-origin coordinates) for each match.
|
|
69
|
+
*/
|
|
70
|
+
export declare function findTextRegions(pdfBytes: Uint8Array, patterns: RedactionPattern[]): Promise<RedactionRegion[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Redact text matching patterns from a PDF.
|
|
73
|
+
*
|
|
74
|
+
* Convenience wrapper: finds all text matching the patterns, then
|
|
75
|
+
* applies coordinate-based redaction to each match.
|
|
76
|
+
*/
|
|
77
|
+
export declare function redactText(pdfBytes: Uint8Array, patterns: RedactionPattern[]): Promise<Uint8Array>;
|
|
78
|
+
/**
|
|
79
|
+
* Merge multiple PDF documents into a single PDF.
|
|
80
|
+
*
|
|
81
|
+
* @param pdfs - Array of PDF byte arrays to merge in order.
|
|
82
|
+
* @returns The merged PDF as a Uint8Array.
|
|
83
|
+
*/
|
|
84
|
+
export declare function mergePdfs(pdfs: Uint8Array[]): Promise<Uint8Array>;
|
|
61
85
|
/**
|
|
62
86
|
* Extract embedded JSON data from a Forme-generated PDF.
|
|
63
87
|
* Uses the browser-native DecompressionStream API (no node:zlib).
|
package/dist/browser.js
CHANGED
|
@@ -172,11 +172,56 @@ export async function renderTemplateWithLayout(templateJson, dataJson) {
|
|
|
172
172
|
const result = wasmRenderTemplatePdfWithLayout(templateJson, dataJson);
|
|
173
173
|
return result;
|
|
174
174
|
}
|
|
175
|
-
// ── PDF
|
|
176
|
-
export async function
|
|
175
|
+
// ── PDF certification ────────────────────────────────────────────────
|
|
176
|
+
export async function certifyPdf(pdfBytes, config) {
|
|
177
177
|
await ensureInit();
|
|
178
|
-
const {
|
|
179
|
-
return
|
|
178
|
+
const { certify_pdf } = await import('../pkg/forme.js');
|
|
179
|
+
return certify_pdf(pdfBytes, JSON.stringify(config));
|
|
180
|
+
}
|
|
181
|
+
/** @deprecated Use certifyPdf */
|
|
182
|
+
export const signPdf = certifyPdf;
|
|
183
|
+
// ── PDF redaction ────────────────────────────────────────────────────
|
|
184
|
+
export async function redactPdf(pdfBytes, regions) {
|
|
185
|
+
await ensureInit();
|
|
186
|
+
const { redact_pdf } = await import('../pkg/forme.js');
|
|
187
|
+
return redact_pdf(pdfBytes, JSON.stringify(regions));
|
|
188
|
+
}
|
|
189
|
+
// ── Text-search redaction ─────────────────────────────────────────────
|
|
190
|
+
/**
|
|
191
|
+
* Find text regions matching patterns in a PDF.
|
|
192
|
+
*
|
|
193
|
+
* Searches PDF content streams for literal or regex patterns and returns
|
|
194
|
+
* redaction regions (in web top-origin coordinates) for each match.
|
|
195
|
+
*/
|
|
196
|
+
export async function findTextRegions(pdfBytes, patterns) {
|
|
197
|
+
await ensureInit();
|
|
198
|
+
const { find_text_regions } = await import('../pkg/forme.js');
|
|
199
|
+
const json = find_text_regions(pdfBytes, JSON.stringify(patterns));
|
|
200
|
+
return JSON.parse(json);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Redact text matching patterns from a PDF.
|
|
204
|
+
*
|
|
205
|
+
* Convenience wrapper: finds all text matching the patterns, then
|
|
206
|
+
* applies coordinate-based redaction to each match.
|
|
207
|
+
*/
|
|
208
|
+
export async function redactText(pdfBytes, patterns) {
|
|
209
|
+
await ensureInit();
|
|
210
|
+
const { redact_text } = await import('../pkg/forme.js');
|
|
211
|
+
return redact_text(pdfBytes, JSON.stringify(patterns));
|
|
212
|
+
}
|
|
213
|
+
// ── PDF merging ──────────────────────────────────────────────────────
|
|
214
|
+
/**
|
|
215
|
+
* Merge multiple PDF documents into a single PDF.
|
|
216
|
+
*
|
|
217
|
+
* @param pdfs - Array of PDF byte arrays to merge in order.
|
|
218
|
+
* @returns The merged PDF as a Uint8Array.
|
|
219
|
+
*/
|
|
220
|
+
export async function mergePdfs(pdfs) {
|
|
221
|
+
await ensureInit();
|
|
222
|
+
const { merge_pdfs } = await import('../pkg/forme.js');
|
|
223
|
+
const base64Pdfs = pdfs.map((pdf) => btoa(Array.from(pdf, (b) => String.fromCharCode(b)).join('')));
|
|
224
|
+
return merge_pdfs(JSON.stringify(base64Pdfs));
|
|
180
225
|
}
|
|
181
226
|
// ── Data extraction (browser-native decompression) ──────────────────
|
|
182
227
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ 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
|
|
75
|
+
export interface CertificationConfig {
|
|
76
76
|
certificatePem: string;
|
|
77
77
|
privateKeyPem: string;
|
|
78
78
|
reason?: string;
|
|
@@ -85,6 +85,8 @@ export interface SignatureConfig {
|
|
|
85
85
|
width?: number;
|
|
86
86
|
height?: number;
|
|
87
87
|
}
|
|
88
|
+
/** @deprecated Use CertificationConfig */
|
|
89
|
+
export type SignatureConfig = CertificationConfig;
|
|
88
90
|
export interface RenderDocumentOptions {
|
|
89
91
|
/** Data to embed as a hidden JSON attachment in the PDF. */
|
|
90
92
|
embedData?: unknown;
|
|
@@ -95,5 +97,53 @@ export declare function renderDocument(element: ReactElement, options?: RenderDo
|
|
|
95
97
|
export declare function renderDocumentWithLayout(element: ReactElement, options?: RenderDocumentOptions): Promise<RenderWithLayoutResult>;
|
|
96
98
|
export declare function renderTemplate(templateJson: string, dataJson: string): Promise<Uint8Array>;
|
|
97
99
|
export declare function renderTemplateWithLayout(templateJson: string, dataJson: string): Promise<RenderWithLayoutResult>;
|
|
98
|
-
export declare function
|
|
100
|
+
export declare function certifyPdf(pdfBytes: Uint8Array, config: CertificationConfig): Promise<Uint8Array>;
|
|
101
|
+
/** @deprecated Use certifyPdf */
|
|
102
|
+
export declare const signPdf: typeof certifyPdf;
|
|
103
|
+
export interface RedactionRegion {
|
|
104
|
+
/** 0-indexed page number. */
|
|
105
|
+
page: number;
|
|
106
|
+
/** X coordinate in points from the left edge. */
|
|
107
|
+
x: number;
|
|
108
|
+
/** Y coordinate in points from the top edge (web/screen coordinates). */
|
|
109
|
+
y: number;
|
|
110
|
+
/** Width of the redaction rectangle in points. */
|
|
111
|
+
width: number;
|
|
112
|
+
/** Height of the redaction rectangle in points. */
|
|
113
|
+
height: number;
|
|
114
|
+
/** Fill color as hex string (e.g. "#000000"). Defaults to black. */
|
|
115
|
+
color?: string;
|
|
116
|
+
}
|
|
117
|
+
export declare function redactPdf(pdfBytes: Uint8Array, regions: RedactionRegion[]): Promise<Uint8Array>;
|
|
118
|
+
export interface RedactionPattern {
|
|
119
|
+
/** The text or regex pattern to search for. */
|
|
120
|
+
pattern: string;
|
|
121
|
+
/** 'Literal' for exact text match (case-insensitive), 'Regex' for regex. */
|
|
122
|
+
pattern_type: 'Literal' | 'Regex';
|
|
123
|
+
/** Optional 0-indexed page to restrict search to. */
|
|
124
|
+
page?: number;
|
|
125
|
+
/** Fill color as hex string (e.g. "#000000"). Defaults to black. */
|
|
126
|
+
color?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Find text regions matching patterns in a PDF.
|
|
130
|
+
*
|
|
131
|
+
* Searches PDF content streams for literal or regex patterns and returns
|
|
132
|
+
* redaction regions (in web top-origin coordinates) for each match.
|
|
133
|
+
*/
|
|
134
|
+
export declare function findTextRegions(pdfBytes: Uint8Array, patterns: RedactionPattern[]): Promise<RedactionRegion[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Redact text matching patterns from a PDF.
|
|
137
|
+
*
|
|
138
|
+
* Convenience wrapper: finds all text matching the patterns, then
|
|
139
|
+
* applies coordinate-based redaction to each match.
|
|
140
|
+
*/
|
|
141
|
+
export declare function redactText(pdfBytes: Uint8Array, patterns: RedactionPattern[]): Promise<Uint8Array>;
|
|
142
|
+
/**
|
|
143
|
+
* Merge multiple PDF documents into a single PDF.
|
|
144
|
+
*
|
|
145
|
+
* @param pdfs - Array of PDF byte arrays to merge in order.
|
|
146
|
+
* @returns The merged PDF as a Uint8Array.
|
|
147
|
+
*/
|
|
148
|
+
export declare function mergePdfs(pdfs: Uint8Array[]): Promise<Uint8Array>;
|
|
99
149
|
export { extractData } from './extract.js';
|
package/dist/index.js
CHANGED
|
@@ -109,11 +109,54 @@ export async function renderTemplateWithLayout(templateJson, dataJson) {
|
|
|
109
109
|
const result = render_template_pdf_with_layout(templateJson, dataJson);
|
|
110
110
|
return result;
|
|
111
111
|
}
|
|
112
|
-
// ── PDF
|
|
113
|
-
export async function
|
|
112
|
+
// ── PDF certification ────────────────────────────────────────────────
|
|
113
|
+
export async function certifyPdf(pdfBytes, config) {
|
|
114
114
|
await ensureInit();
|
|
115
|
-
const {
|
|
116
|
-
return
|
|
115
|
+
const { certify_pdf } = await import('../pkg/forme.js');
|
|
116
|
+
return certify_pdf(pdfBytes, JSON.stringify(config));
|
|
117
|
+
}
|
|
118
|
+
/** @deprecated Use certifyPdf */
|
|
119
|
+
export const signPdf = certifyPdf;
|
|
120
|
+
export async function redactPdf(pdfBytes, regions) {
|
|
121
|
+
await ensureInit();
|
|
122
|
+
const { redact_pdf } = await import('../pkg/forme.js');
|
|
123
|
+
return redact_pdf(pdfBytes, JSON.stringify(regions));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Find text regions matching patterns in a PDF.
|
|
127
|
+
*
|
|
128
|
+
* Searches PDF content streams for literal or regex patterns and returns
|
|
129
|
+
* redaction regions (in web top-origin coordinates) for each match.
|
|
130
|
+
*/
|
|
131
|
+
export async function findTextRegions(pdfBytes, patterns) {
|
|
132
|
+
await ensureInit();
|
|
133
|
+
const { find_text_regions } = await import('../pkg/forme.js');
|
|
134
|
+
const json = find_text_regions(pdfBytes, JSON.stringify(patterns));
|
|
135
|
+
return JSON.parse(json);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Redact text matching patterns from a PDF.
|
|
139
|
+
*
|
|
140
|
+
* Convenience wrapper: finds all text matching the patterns, then
|
|
141
|
+
* applies coordinate-based redaction to each match.
|
|
142
|
+
*/
|
|
143
|
+
export async function redactText(pdfBytes, patterns) {
|
|
144
|
+
await ensureInit();
|
|
145
|
+
const { redact_text } = await import('../pkg/forme.js');
|
|
146
|
+
return redact_text(pdfBytes, JSON.stringify(patterns));
|
|
147
|
+
}
|
|
148
|
+
// ── PDF merging ──────────────────────────────────────────────────────
|
|
149
|
+
/**
|
|
150
|
+
* Merge multiple PDF documents into a single PDF.
|
|
151
|
+
*
|
|
152
|
+
* @param pdfs - Array of PDF byte arrays to merge in order.
|
|
153
|
+
* @returns The merged PDF as a Uint8Array.
|
|
154
|
+
*/
|
|
155
|
+
export async function mergePdfs(pdfs) {
|
|
156
|
+
await ensureInit();
|
|
157
|
+
const { merge_pdfs } = await import('../pkg/forme.js');
|
|
158
|
+
const base64Pdfs = pdfs.map((pdf) => Buffer.from(pdf).toString('base64'));
|
|
159
|
+
return merge_pdfs(JSON.stringify(base64Pdfs));
|
|
117
160
|
}
|
|
118
161
|
// ── Data extraction ──────────────────────────────────────────────────
|
|
119
162
|
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.9.1",
|
|
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.9.1"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"react": "^18 || ^19"
|
package/pkg/README.md
CHANGED
|
@@ -50,12 +50,26 @@ fn main() -> Result<(), FormeError> {
|
|
|
50
50
|
|
|
51
51
|
## API
|
|
52
52
|
|
|
53
|
+
### Rendering
|
|
54
|
+
|
|
53
55
|
| Function | Description |
|
|
54
56
|
|----------|-------------|
|
|
55
57
|
| `render(&Document)` | Render a document struct to PDF bytes |
|
|
56
58
|
| `render_json(&str)` | Parse JSON and render to PDF bytes |
|
|
57
|
-
| `render_with_layout(&Document)` | Render and return layout metadata |
|
|
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 |
|
|
58
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 |
|
|
59
73
|
|
|
60
74
|
All functions return `Result<Vec<u8>, FormeError>` (or a tuple with `LayoutInfo` for the `_with_layout` variants).
|
|
61
75
|
|
package/pkg/forme.d.ts
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
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
|
+
|
|
4
33
|
export function render_pdf(json: string): Uint8Array;
|
|
5
34
|
|
|
6
35
|
export function render_pdf_with_layout(json: string): any;
|
|
@@ -9,27 +38,27 @@ export function render_template_pdf(template_json: string, data_json: string): U
|
|
|
9
38
|
|
|
10
39
|
export function render_template_pdf_with_layout(template_json: string, data_json: string): any;
|
|
11
40
|
|
|
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
|
-
|
|
17
41
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
18
42
|
|
|
19
43
|
export interface InitOutput {
|
|
20
44
|
readonly memory: WebAssembly.Memory;
|
|
45
|
+
readonly certify_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
46
|
+
readonly find_text_regions: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
47
|
+
readonly merge_pdfs: (a: number, b: number) => [number, number, number, number];
|
|
48
|
+
readonly redact_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
49
|
+
readonly redact_text: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
21
50
|
readonly render_pdf: (a: number, b: number) => [number, number, number, number];
|
|
22
51
|
readonly render_pdf_with_layout: (a: number, b: number) => [number, number, number];
|
|
23
52
|
readonly render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
24
53
|
readonly render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
25
|
-
readonly
|
|
54
|
+
readonly init_panic_hook: () => void;
|
|
26
55
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
27
56
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
57
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
28
58
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
29
59
|
readonly __externref_table_alloc: () => number;
|
|
30
60
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
31
61
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
32
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
33
62
|
readonly __wbindgen_start: () => void;
|
|
34
63
|
}
|
|
35
64
|
|
package/pkg/forme.js
CHANGED
|
@@ -1,5 +1,117 @@
|
|
|
1
1
|
/* @ts-self-types="./forme.d.ts" */
|
|
2
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
|
+
export 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
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Find text regions matching patterns in a PDF.
|
|
25
|
+
* Returns JSON string of Vec<RedactionRegion>.
|
|
26
|
+
* @param {Uint8Array} pdf_bytes
|
|
27
|
+
* @param {string} patterns_json
|
|
28
|
+
* @returns {string}
|
|
29
|
+
*/
|
|
30
|
+
export function find_text_regions(pdf_bytes, patterns_json) {
|
|
31
|
+
let deferred4_0;
|
|
32
|
+
let deferred4_1;
|
|
33
|
+
try {
|
|
34
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
35
|
+
const len0 = WASM_VECTOR_LEN;
|
|
36
|
+
const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
37
|
+
const len1 = WASM_VECTOR_LEN;
|
|
38
|
+
const ret = wasm.find_text_regions(ptr0, len0, ptr1, len1);
|
|
39
|
+
var ptr3 = ret[0];
|
|
40
|
+
var len3 = ret[1];
|
|
41
|
+
if (ret[3]) {
|
|
42
|
+
ptr3 = 0; len3 = 0;
|
|
43
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
44
|
+
}
|
|
45
|
+
deferred4_0 = ptr3;
|
|
46
|
+
deferred4_1 = len3;
|
|
47
|
+
return getStringFromWasm0(ptr3, len3);
|
|
48
|
+
} finally {
|
|
49
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function init_panic_hook() {
|
|
54
|
+
wasm.init_panic_hook();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Merge multiple PDFs into a single document.
|
|
59
|
+
* Accepts a JSON array of base64-encoded PDF strings.
|
|
60
|
+
* @param {string} pdfs_json
|
|
61
|
+
* @returns {Uint8Array}
|
|
62
|
+
*/
|
|
63
|
+
export function merge_pdfs(pdfs_json) {
|
|
64
|
+
const ptr0 = passStringToWasm0(pdfs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
65
|
+
const len0 = WASM_VECTOR_LEN;
|
|
66
|
+
const ret = wasm.merge_pdfs(ptr0, len0);
|
|
67
|
+
if (ret[3]) {
|
|
68
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
69
|
+
}
|
|
70
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
71
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
72
|
+
return v2;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Redact regions of a PDF by overlaying opaque rectangles.
|
|
77
|
+
* @param {Uint8Array} pdf_bytes
|
|
78
|
+
* @param {string} redactions_json
|
|
79
|
+
* @returns {Uint8Array}
|
|
80
|
+
*/
|
|
81
|
+
export function redact_pdf(pdf_bytes, redactions_json) {
|
|
82
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
83
|
+
const len0 = WASM_VECTOR_LEN;
|
|
84
|
+
const ptr1 = passStringToWasm0(redactions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
85
|
+
const len1 = WASM_VECTOR_LEN;
|
|
86
|
+
const ret = wasm.redact_pdf(ptr0, len0, ptr1, len1);
|
|
87
|
+
if (ret[3]) {
|
|
88
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
89
|
+
}
|
|
90
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
91
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
92
|
+
return v3;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Redact text matching patterns from a PDF.
|
|
97
|
+
* @param {Uint8Array} pdf_bytes
|
|
98
|
+
* @param {string} patterns_json
|
|
99
|
+
* @returns {Uint8Array}
|
|
100
|
+
*/
|
|
101
|
+
export function redact_text(pdf_bytes, patterns_json) {
|
|
102
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
103
|
+
const len0 = WASM_VECTOR_LEN;
|
|
104
|
+
const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
105
|
+
const len1 = WASM_VECTOR_LEN;
|
|
106
|
+
const ret = wasm.redact_text(ptr0, len0, ptr1, len1);
|
|
107
|
+
if (ret[3]) {
|
|
108
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
109
|
+
}
|
|
110
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
111
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
112
|
+
return v3;
|
|
113
|
+
}
|
|
114
|
+
|
|
3
115
|
/**
|
|
4
116
|
* @param {string} json
|
|
5
117
|
* @returns {Uint8Array}
|
|
@@ -66,26 +178,6 @@ export function render_template_pdf_with_layout(template_json, data_json) {
|
|
|
66
178
|
return takeFromExternrefTable0(ret[0]);
|
|
67
179
|
}
|
|
68
180
|
|
|
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
|
-
|
|
89
181
|
function __wbg_get_imports() {
|
|
90
182
|
const import0 = {
|
|
91
183
|
__proto__: null,
|
|
@@ -99,6 +191,17 @@ function __wbg_get_imports() {
|
|
|
99
191
|
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
100
192
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
101
193
|
},
|
|
194
|
+
__wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
|
|
195
|
+
let deferred0_0;
|
|
196
|
+
let deferred0_1;
|
|
197
|
+
try {
|
|
198
|
+
deferred0_0 = arg0;
|
|
199
|
+
deferred0_1 = arg1;
|
|
200
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
201
|
+
} finally {
|
|
202
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
102
205
|
__wbg_new_361308b2356cecd0: function() {
|
|
103
206
|
const ret = new Object();
|
|
104
207
|
return ret;
|
|
@@ -107,10 +210,18 @@ function __wbg_get_imports() {
|
|
|
107
210
|
const ret = new Array();
|
|
108
211
|
return ret;
|
|
109
212
|
},
|
|
213
|
+
__wbg_new_8a6f238a6ece86ea: function() {
|
|
214
|
+
const ret = new Error();
|
|
215
|
+
return ret;
|
|
216
|
+
},
|
|
110
217
|
__wbg_new_from_slice_a3d2629dc1826784: function(arg0, arg1) {
|
|
111
218
|
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
112
219
|
return ret;
|
|
113
220
|
},
|
|
221
|
+
__wbg_now_a3af9a2f4bbaa4d1: function() {
|
|
222
|
+
const ret = Date.now();
|
|
223
|
+
return ret;
|
|
224
|
+
},
|
|
114
225
|
__wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
|
|
115
226
|
arg0[arg1] = arg2;
|
|
116
227
|
},
|
|
@@ -121,6 +232,13 @@ function __wbg_get_imports() {
|
|
|
121
232
|
__wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
|
|
122
233
|
arg0[arg1 >>> 0] = arg2;
|
|
123
234
|
},
|
|
235
|
+
__wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
|
|
236
|
+
const ret = arg1.stack;
|
|
237
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
238
|
+
const len1 = WASM_VECTOR_LEN;
|
|
239
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
240
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
241
|
+
},
|
|
124
242
|
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
125
243
|
// Cast intrinsic for `F64 -> Externref`.
|
|
126
244
|
const ret = arg0;
|
package/pkg/forme_bg.wasm
CHANGED
|
Binary file
|
package/pkg/forme_bg.wasm.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
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];
|
|
4
9
|
export const render_pdf: (a: number, b: number) => [number, number, number, number];
|
|
5
10
|
export const render_pdf_with_layout: (a: number, b: number) => [number, number, number];
|
|
6
11
|
export const render_template_pdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
7
12
|
export const render_template_pdf_with_layout: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
8
|
-
export const
|
|
13
|
+
export const init_panic_hook: () => void;
|
|
9
14
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
10
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;
|
|
11
17
|
export const __wbindgen_exn_store: (a: number) => void;
|
|
12
18
|
export const __externref_table_alloc: () => number;
|
|
13
19
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
14
20
|
export const __externref_table_dealloc: (a: number) => void;
|
|
15
|
-
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
16
21
|
export const __wbindgen_start: () => void;
|
package/pkg/package.json
CHANGED