@unlev/exeq 0.3.1 → 0.3.2
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/README.md +102 -2
- package/dist/index.d.mts +116 -2
- package/dist/index.d.ts +116 -2
- package/dist/index.js +254 -139
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +253 -140
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,13 +148,113 @@ import { renderPdfPages, generateFilledPdf, downloadPdf } from '@unlev/exeq';
|
|
|
148
148
|
// Render PDF pages to images
|
|
149
149
|
const pages = await renderPdfPages(pdfUrlOrBytes);
|
|
150
150
|
|
|
151
|
-
// Generate a filled PDF
|
|
152
|
-
const bytes = await generateFilledPdf(pdfSource, fields);
|
|
151
|
+
// Generate a filled PDF
|
|
152
|
+
const bytes = await generateFilledPdf({ pdfSource, fields });
|
|
153
153
|
|
|
154
154
|
// Trigger browser download
|
|
155
155
|
downloadPdf(bytes, 'signed-document.pdf');
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
### `generateFilledPdf`
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
generateFilledPdf(opts: FillPdfOptions): Promise<Uint8Array>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { generateFilledPdf, US_LETTER } from '@unlev/exeq';
|
|
166
|
+
|
|
167
|
+
// Overlay-only: blank Letter pages with no background — for printing
|
|
168
|
+
// onto pre-printed physical forms.
|
|
169
|
+
const overlay = await generateFilledPdf({
|
|
170
|
+
pdfSource: null,
|
|
171
|
+
fields,
|
|
172
|
+
pageSize: US_LETTER,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Always-Letter output even when the source PDF isn't Letter — useful
|
|
176
|
+
// when the source is a scan at slightly different dimensions.
|
|
177
|
+
const letter = await generateFilledPdf({
|
|
178
|
+
pdfSource: '/forms/template.pdf',
|
|
179
|
+
fields,
|
|
180
|
+
pageSize: US_LETTER,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Resolve formula fields during render.
|
|
184
|
+
const filled = await generateFilledPdf({
|
|
185
|
+
pdfSource,
|
|
186
|
+
fields,
|
|
187
|
+
resolveFormulas: true,
|
|
188
|
+
customTransforms: { last4: v => v.slice(-4) },
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
| Option | Type | Description |
|
|
193
|
+
|--------|------|-------------|
|
|
194
|
+
| `pdfSource` | `string \| ArrayBuffer \| null` | Background PDF (URL or bytes), or `null` for overlay-only output. |
|
|
195
|
+
| `fields` | `FormField[]` | Fields to render on top of the background. |
|
|
196
|
+
| `pageSize` | `[number, number]` | Override output page size in PDF points (72pt = 1in). With a source, source pages are drawn stretched to fit. Defaults to source dims, or Letter if no source. |
|
|
197
|
+
| `pageCount` | `number` | When `pdfSource` is null, how many blank pages to render. Default `1`. |
|
|
198
|
+
| `resolveFormulas` | `boolean` | Run `resolveAllFormulas` on fields before rendering. Default `false`. |
|
|
199
|
+
| `customTransforms` | `TransformMap` | Merged with `BUILTIN_TRANSFORMS` during formula resolution. |
|
|
200
|
+
| `calibration` | `Calibration` | Linear offset/scale applied to field positions. |
|
|
201
|
+
|
|
202
|
+
### `createPdfBuilder` — batch / mail merge
|
|
203
|
+
|
|
204
|
+
For multi-record output (e.g. one PDF with one page per recipient), `createPdfBuilder` merges records into a single document and dedupes shared resources — the source PDF, fonts, and signature PNGs are embedded once and referenced from every page.
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import { createPdfBuilder, downloadPdf, US_LETTER } from '@unlev/exeq';
|
|
208
|
+
|
|
209
|
+
const builder = await createPdfBuilder({ pageSize: US_LETTER });
|
|
210
|
+
for (const record of records) {
|
|
211
|
+
await builder.addRecord({
|
|
212
|
+
pdfSource: '/forms/template.pdf', // embedded once, referenced N times
|
|
213
|
+
fields: record.fields,
|
|
214
|
+
resolveFormulas: true,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
const bytes = await builder.save();
|
|
218
|
+
downloadPdf(bytes, 'merged.pdf');
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
A 12-record batch with a 700 KB background goes from ~8 MB (12 separate `generateFilledPdf` calls, then merged with `pdf-lib`) to ~705 KB (one embed shared across pages).
|
|
222
|
+
|
|
223
|
+
`PdfBuilder.doc` exposes the underlying `pdf-lib` document if you need to add an audit trail or table-of-contents page before saving.
|
|
224
|
+
|
|
225
|
+
### Calibration
|
|
226
|
+
|
|
227
|
+
When a printed overlay doesn't quite register with a pre-printed physical form (because the scan was cropped differently than the real paper, or the printer tray has a small offset), apply a linear calibration. Offsets are in PDF points (72pt = 1 inch).
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { applyCalibration, generateFilledPdf, US_LETTER } from '@unlev/exeq';
|
|
231
|
+
|
|
232
|
+
// Either pass calibration to the renderer:
|
|
233
|
+
const bytes = await generateFilledPdf(pdfSource, fields, {
|
|
234
|
+
pageSize: US_LETTER,
|
|
235
|
+
calibration: { xOffset: -5, yOffset: 3, xScale: 1.005, yScale: 1 },
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// …or apply it as a standalone transform (useful for previews):
|
|
239
|
+
const adjusted = applyCalibration(fields, { xOffset: -5, yOffset: 3, xScale: 1.005, yScale: 1 });
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
| Field | Type | Meaning |
|
|
243
|
+
|-------|------|---------|
|
|
244
|
+
| `xOffset` | `number` (pt) | Horizontal shift; positive = right. |
|
|
245
|
+
| `yOffset` | `number` (pt) | Vertical shift; positive = down (screen coords). |
|
|
246
|
+
| `xScale` | `number` | Multiplier on x and width. |
|
|
247
|
+
| `yScale` | `number` | Multiplier on y and height. |
|
|
248
|
+
|
|
249
|
+
### Page-size constants
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
import { US_LETTER, US_LEGAL, A4 } from '@unlev/exeq';
|
|
253
|
+
// US_LETTER === [612, 792]
|
|
254
|
+
// US_LEGAL === [612, 1008]
|
|
255
|
+
// A4 === [595.28, 841.89]
|
|
256
|
+
```
|
|
257
|
+
|
|
158
258
|
### Types
|
|
159
259
|
|
|
160
260
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PDFDocument } from 'pdf-lib';
|
|
2
3
|
|
|
3
4
|
declare function generateId(): string;
|
|
4
5
|
type FieldType = 'text' | 'dropdown' | 'signature' | 'signed-date' | 'checkbox' | 'initials' | 'blackout' | 'whiteout';
|
|
@@ -27,6 +28,7 @@ interface FormField {
|
|
|
27
28
|
options?: string[];
|
|
28
29
|
formula?: string;
|
|
29
30
|
locked?: boolean;
|
|
31
|
+
autoShrink?: boolean;
|
|
30
32
|
}
|
|
31
33
|
interface Template {
|
|
32
34
|
fields: FormField[];
|
|
@@ -193,8 +195,120 @@ interface SignerRoleSelectorProps {
|
|
|
193
195
|
}
|
|
194
196
|
declare function SignerRoleSelector({ roles, activeRole, onSetActiveRole, onAddRole, onRemoveRole, }: SignerRoleSelectorProps): react_jsx_runtime.JSX.Element;
|
|
195
197
|
|
|
196
|
-
|
|
198
|
+
/** US Letter in PDF points (72pt = 1 in). */
|
|
199
|
+
declare const US_LETTER: [number, number];
|
|
200
|
+
/** US Legal in PDF points. */
|
|
201
|
+
declare const US_LEGAL: [number, number];
|
|
202
|
+
/** A4 in PDF points. */
|
|
203
|
+
declare const A4: [number, number];
|
|
204
|
+
/**
|
|
205
|
+
* Linear calibration applied to every field's percentage position and size.
|
|
206
|
+
* Use to align rendered output with a physical pre-printed form when the
|
|
207
|
+
* template's source PDF and the real paper don't exactly agree on crop or
|
|
208
|
+
* scale.
|
|
209
|
+
*
|
|
210
|
+
* Math (for an output page of size [pW, pH] pt):
|
|
211
|
+
* xPctOff = (xOffset / pW) * 100
|
|
212
|
+
* yPctOff = (yOffset / pH) * 100
|
|
213
|
+
* x' = x_pct * xScale + xPctOff
|
|
214
|
+
* y' = y_pct * yScale + yPctOff
|
|
215
|
+
* width' = width_pct * xScale
|
|
216
|
+
* height' = height_pct * yScale
|
|
217
|
+
*
|
|
218
|
+
* Defaults (scale=1, offsets=0) are a no-op.
|
|
219
|
+
*/
|
|
220
|
+
interface Calibration {
|
|
221
|
+
/** Horizontal offset in PDF points; positive = right. */
|
|
222
|
+
xOffset: number;
|
|
223
|
+
/** Vertical offset in PDF points; positive = down (screen coords). */
|
|
224
|
+
yOffset: number;
|
|
225
|
+
/** Horizontal multiplier applied to x and width. */
|
|
226
|
+
xScale: number;
|
|
227
|
+
/** Vertical multiplier applied to y and height. */
|
|
228
|
+
yScale: number;
|
|
229
|
+
}
|
|
230
|
+
declare const DEFAULT_CALIBRATION: Calibration;
|
|
231
|
+
/**
|
|
232
|
+
* Returns a copy of `fields` with calibration applied to x / y / width /
|
|
233
|
+
* height. The math is page-size-aware so an `xOffset` of 5pt actually
|
|
234
|
+
* shifts the rendered output 5pt to the right.
|
|
235
|
+
*
|
|
236
|
+
* @param pageSize Output page size in pt used to convert pt offsets to
|
|
237
|
+
* percent offsets. Defaults to US Letter.
|
|
238
|
+
*/
|
|
239
|
+
declare function applyCalibration(fields: FormField[], calibration: Calibration, pageSize?: [number, number]): FormField[];
|
|
240
|
+
interface FillPdfOptions {
|
|
241
|
+
/** Source PDF used as the background.
|
|
242
|
+
* - `string` (URL): fetched, embedded once per URL across the document.
|
|
243
|
+
* - `ArrayBuffer`: embedded uniquely each call.
|
|
244
|
+
* - `null`: render onto blank pages (overlay-only output). */
|
|
245
|
+
pdfSource: string | ArrayBuffer | null;
|
|
246
|
+
/** Fields to render on top of the background. */
|
|
247
|
+
fields: FormField[];
|
|
248
|
+
/** Override the output page size in PDF points.
|
|
249
|
+
* - With a `pdfSource`, source pages are drawn stretched to fit.
|
|
250
|
+
* - With `pdfSource: null`, blank pages of this size are created.
|
|
251
|
+
* - When omitted with a source, output uses the source's page sizes.
|
|
252
|
+
* - When omitted with `pdfSource: null`, defaults to US Letter. */
|
|
253
|
+
pageSize?: [number, number];
|
|
254
|
+
/** When `pdfSource` is null, how many blank pages to render. Default `1`.
|
|
255
|
+
* Fields with out-of-range `page` indices are skipped. */
|
|
256
|
+
pageCount?: number;
|
|
257
|
+
/** Run `resolveAllFormulas` on fields before rendering. */
|
|
258
|
+
resolveFormulas?: boolean;
|
|
259
|
+
/** Custom transforms merged with `BUILTIN_TRANSFORMS` during formula
|
|
260
|
+
* resolution. Only meaningful when `resolveFormulas` is true. */
|
|
261
|
+
customTransforms?: TransformMap;
|
|
262
|
+
/** Linear calibration applied to field positions before rendering. */
|
|
263
|
+
calibration?: Calibration;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Generates one filled PDF.
|
|
267
|
+
*
|
|
268
|
+
* const bytes = await generateFilledPdf({
|
|
269
|
+
* pdfSource: '/forms/template.pdf',
|
|
270
|
+
* fields: template.fields,
|
|
271
|
+
* pageSize: US_LETTER,
|
|
272
|
+
* resolveFormulas: true,
|
|
273
|
+
* });
|
|
274
|
+
*
|
|
275
|
+
* For multi-record output that shares a background, use `createPdfBuilder`
|
|
276
|
+
* — it dedupes the embedded source across all pages.
|
|
277
|
+
*/
|
|
278
|
+
declare function generateFilledPdf(opts: FillPdfOptions): Promise<Uint8Array>;
|
|
279
|
+
interface PdfBuilder {
|
|
280
|
+
/** Underlying pdf-lib document — exposed for advanced post-processing
|
|
281
|
+
* (audit-trail pages, custom metadata, etc.). */
|
|
282
|
+
readonly doc: PDFDocument;
|
|
283
|
+
/** Append one record's pages to the output. */
|
|
284
|
+
addRecord(opts: FillPdfOptions): Promise<void>;
|
|
285
|
+
/** Finalize and return the merged PDF bytes. */
|
|
286
|
+
save(): Promise<Uint8Array>;
|
|
287
|
+
}
|
|
288
|
+
interface CreatePdfBuilderOptions {
|
|
289
|
+
/** Default `pageSize` for any `addRecord` call that doesn't set its own. */
|
|
290
|
+
pageSize?: [number, number];
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Creates a builder that merges multiple filled records into one PDF.
|
|
294
|
+
*
|
|
295
|
+
* Resources (source PDFs indexed by URL, embedded fonts, signature PNGs) are
|
|
296
|
+
* embedded once across the whole document and reused — critical for
|
|
297
|
+
* mail-merge style batches where dozens of records share the same background.
|
|
298
|
+
*
|
|
299
|
+
* const builder = await createPdfBuilder({ pageSize: US_LETTER });
|
|
300
|
+
* for (const record of records) {
|
|
301
|
+
* await builder.addRecord({
|
|
302
|
+
* pdfSource: '/forms/template.pdf',
|
|
303
|
+
* fields: record.fields,
|
|
304
|
+
* resolveFormulas: true,
|
|
305
|
+
* });
|
|
306
|
+
* }
|
|
307
|
+
* const bytes = await builder.save();
|
|
308
|
+
* downloadPdf(bytes, 'merged.pdf');
|
|
309
|
+
*/
|
|
310
|
+
declare function createPdfBuilder(defaults?: CreatePdfBuilderOptions): Promise<PdfBuilder>;
|
|
197
311
|
declare function downloadPdf(bytes: Uint8Array, filename: string): void;
|
|
198
312
|
declare function postPdfToCallback(bytes: Uint8Array, callbackUrl: string, filename: string): Promise<void>;
|
|
199
313
|
|
|
200
|
-
export { BUILTIN_TRANSFORMS, DEFAULT_SIGNER_ROLES, DesignerView, type DesignerViewProps, FIELD_DEFAULTS, FONT_FAMILIES, FieldNavigator, FieldPropertyPanel, type FieldType, type FormField, PdfViewer, type RenderedPage, SIGNER_ROLE_COLORS, SignatureCanvas, SignerRoleSelector, SignerView, type SignerViewProps, type Template, type TextSubtype, type TransformFn, type TransformMap, createField, downloadPdf, generateFilledPdf, generateId, getSignerColor, postPdfToCallback, renderPdfPages, resolveAllFormulas, resolveFormula, uniqueLabel };
|
|
314
|
+
export { A4, BUILTIN_TRANSFORMS, type Calibration, type CreatePdfBuilderOptions, DEFAULT_CALIBRATION, DEFAULT_SIGNER_ROLES, DesignerView, type DesignerViewProps, FIELD_DEFAULTS, FONT_FAMILIES, FieldNavigator, FieldPropertyPanel, type FieldType, type FillPdfOptions, type FormField, type PdfBuilder, PdfViewer, type RenderedPage, SIGNER_ROLE_COLORS, SignatureCanvas, SignerRoleSelector, SignerView, type SignerViewProps, type Template, type TextSubtype, type TransformFn, type TransformMap, US_LEGAL, US_LETTER, applyCalibration, createField, createPdfBuilder, downloadPdf, generateFilledPdf, generateId, getSignerColor, postPdfToCallback, renderPdfPages, resolveAllFormulas, resolveFormula, uniqueLabel };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PDFDocument } from 'pdf-lib';
|
|
2
3
|
|
|
3
4
|
declare function generateId(): string;
|
|
4
5
|
type FieldType = 'text' | 'dropdown' | 'signature' | 'signed-date' | 'checkbox' | 'initials' | 'blackout' | 'whiteout';
|
|
@@ -27,6 +28,7 @@ interface FormField {
|
|
|
27
28
|
options?: string[];
|
|
28
29
|
formula?: string;
|
|
29
30
|
locked?: boolean;
|
|
31
|
+
autoShrink?: boolean;
|
|
30
32
|
}
|
|
31
33
|
interface Template {
|
|
32
34
|
fields: FormField[];
|
|
@@ -193,8 +195,120 @@ interface SignerRoleSelectorProps {
|
|
|
193
195
|
}
|
|
194
196
|
declare function SignerRoleSelector({ roles, activeRole, onSetActiveRole, onAddRole, onRemoveRole, }: SignerRoleSelectorProps): react_jsx_runtime.JSX.Element;
|
|
195
197
|
|
|
196
|
-
|
|
198
|
+
/** US Letter in PDF points (72pt = 1 in). */
|
|
199
|
+
declare const US_LETTER: [number, number];
|
|
200
|
+
/** US Legal in PDF points. */
|
|
201
|
+
declare const US_LEGAL: [number, number];
|
|
202
|
+
/** A4 in PDF points. */
|
|
203
|
+
declare const A4: [number, number];
|
|
204
|
+
/**
|
|
205
|
+
* Linear calibration applied to every field's percentage position and size.
|
|
206
|
+
* Use to align rendered output with a physical pre-printed form when the
|
|
207
|
+
* template's source PDF and the real paper don't exactly agree on crop or
|
|
208
|
+
* scale.
|
|
209
|
+
*
|
|
210
|
+
* Math (for an output page of size [pW, pH] pt):
|
|
211
|
+
* xPctOff = (xOffset / pW) * 100
|
|
212
|
+
* yPctOff = (yOffset / pH) * 100
|
|
213
|
+
* x' = x_pct * xScale + xPctOff
|
|
214
|
+
* y' = y_pct * yScale + yPctOff
|
|
215
|
+
* width' = width_pct * xScale
|
|
216
|
+
* height' = height_pct * yScale
|
|
217
|
+
*
|
|
218
|
+
* Defaults (scale=1, offsets=0) are a no-op.
|
|
219
|
+
*/
|
|
220
|
+
interface Calibration {
|
|
221
|
+
/** Horizontal offset in PDF points; positive = right. */
|
|
222
|
+
xOffset: number;
|
|
223
|
+
/** Vertical offset in PDF points; positive = down (screen coords). */
|
|
224
|
+
yOffset: number;
|
|
225
|
+
/** Horizontal multiplier applied to x and width. */
|
|
226
|
+
xScale: number;
|
|
227
|
+
/** Vertical multiplier applied to y and height. */
|
|
228
|
+
yScale: number;
|
|
229
|
+
}
|
|
230
|
+
declare const DEFAULT_CALIBRATION: Calibration;
|
|
231
|
+
/**
|
|
232
|
+
* Returns a copy of `fields` with calibration applied to x / y / width /
|
|
233
|
+
* height. The math is page-size-aware so an `xOffset` of 5pt actually
|
|
234
|
+
* shifts the rendered output 5pt to the right.
|
|
235
|
+
*
|
|
236
|
+
* @param pageSize Output page size in pt used to convert pt offsets to
|
|
237
|
+
* percent offsets. Defaults to US Letter.
|
|
238
|
+
*/
|
|
239
|
+
declare function applyCalibration(fields: FormField[], calibration: Calibration, pageSize?: [number, number]): FormField[];
|
|
240
|
+
interface FillPdfOptions {
|
|
241
|
+
/** Source PDF used as the background.
|
|
242
|
+
* - `string` (URL): fetched, embedded once per URL across the document.
|
|
243
|
+
* - `ArrayBuffer`: embedded uniquely each call.
|
|
244
|
+
* - `null`: render onto blank pages (overlay-only output). */
|
|
245
|
+
pdfSource: string | ArrayBuffer | null;
|
|
246
|
+
/** Fields to render on top of the background. */
|
|
247
|
+
fields: FormField[];
|
|
248
|
+
/** Override the output page size in PDF points.
|
|
249
|
+
* - With a `pdfSource`, source pages are drawn stretched to fit.
|
|
250
|
+
* - With `pdfSource: null`, blank pages of this size are created.
|
|
251
|
+
* - When omitted with a source, output uses the source's page sizes.
|
|
252
|
+
* - When omitted with `pdfSource: null`, defaults to US Letter. */
|
|
253
|
+
pageSize?: [number, number];
|
|
254
|
+
/** When `pdfSource` is null, how many blank pages to render. Default `1`.
|
|
255
|
+
* Fields with out-of-range `page` indices are skipped. */
|
|
256
|
+
pageCount?: number;
|
|
257
|
+
/** Run `resolveAllFormulas` on fields before rendering. */
|
|
258
|
+
resolveFormulas?: boolean;
|
|
259
|
+
/** Custom transforms merged with `BUILTIN_TRANSFORMS` during formula
|
|
260
|
+
* resolution. Only meaningful when `resolveFormulas` is true. */
|
|
261
|
+
customTransforms?: TransformMap;
|
|
262
|
+
/** Linear calibration applied to field positions before rendering. */
|
|
263
|
+
calibration?: Calibration;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Generates one filled PDF.
|
|
267
|
+
*
|
|
268
|
+
* const bytes = await generateFilledPdf({
|
|
269
|
+
* pdfSource: '/forms/template.pdf',
|
|
270
|
+
* fields: template.fields,
|
|
271
|
+
* pageSize: US_LETTER,
|
|
272
|
+
* resolveFormulas: true,
|
|
273
|
+
* });
|
|
274
|
+
*
|
|
275
|
+
* For multi-record output that shares a background, use `createPdfBuilder`
|
|
276
|
+
* — it dedupes the embedded source across all pages.
|
|
277
|
+
*/
|
|
278
|
+
declare function generateFilledPdf(opts: FillPdfOptions): Promise<Uint8Array>;
|
|
279
|
+
interface PdfBuilder {
|
|
280
|
+
/** Underlying pdf-lib document — exposed for advanced post-processing
|
|
281
|
+
* (audit-trail pages, custom metadata, etc.). */
|
|
282
|
+
readonly doc: PDFDocument;
|
|
283
|
+
/** Append one record's pages to the output. */
|
|
284
|
+
addRecord(opts: FillPdfOptions): Promise<void>;
|
|
285
|
+
/** Finalize and return the merged PDF bytes. */
|
|
286
|
+
save(): Promise<Uint8Array>;
|
|
287
|
+
}
|
|
288
|
+
interface CreatePdfBuilderOptions {
|
|
289
|
+
/** Default `pageSize` for any `addRecord` call that doesn't set its own. */
|
|
290
|
+
pageSize?: [number, number];
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Creates a builder that merges multiple filled records into one PDF.
|
|
294
|
+
*
|
|
295
|
+
* Resources (source PDFs indexed by URL, embedded fonts, signature PNGs) are
|
|
296
|
+
* embedded once across the whole document and reused — critical for
|
|
297
|
+
* mail-merge style batches where dozens of records share the same background.
|
|
298
|
+
*
|
|
299
|
+
* const builder = await createPdfBuilder({ pageSize: US_LETTER });
|
|
300
|
+
* for (const record of records) {
|
|
301
|
+
* await builder.addRecord({
|
|
302
|
+
* pdfSource: '/forms/template.pdf',
|
|
303
|
+
* fields: record.fields,
|
|
304
|
+
* resolveFormulas: true,
|
|
305
|
+
* });
|
|
306
|
+
* }
|
|
307
|
+
* const bytes = await builder.save();
|
|
308
|
+
* downloadPdf(bytes, 'merged.pdf');
|
|
309
|
+
*/
|
|
310
|
+
declare function createPdfBuilder(defaults?: CreatePdfBuilderOptions): Promise<PdfBuilder>;
|
|
197
311
|
declare function downloadPdf(bytes: Uint8Array, filename: string): void;
|
|
198
312
|
declare function postPdfToCallback(bytes: Uint8Array, callbackUrl: string, filename: string): Promise<void>;
|
|
199
313
|
|
|
200
|
-
export { BUILTIN_TRANSFORMS, DEFAULT_SIGNER_ROLES, DesignerView, type DesignerViewProps, FIELD_DEFAULTS, FONT_FAMILIES, FieldNavigator, FieldPropertyPanel, type FieldType, type FormField, PdfViewer, type RenderedPage, SIGNER_ROLE_COLORS, SignatureCanvas, SignerRoleSelector, SignerView, type SignerViewProps, type Template, type TextSubtype, type TransformFn, type TransformMap, createField, downloadPdf, generateFilledPdf, generateId, getSignerColor, postPdfToCallback, renderPdfPages, resolveAllFormulas, resolveFormula, uniqueLabel };
|
|
314
|
+
export { A4, BUILTIN_TRANSFORMS, type Calibration, type CreatePdfBuilderOptions, DEFAULT_CALIBRATION, DEFAULT_SIGNER_ROLES, DesignerView, type DesignerViewProps, FIELD_DEFAULTS, FONT_FAMILIES, FieldNavigator, FieldPropertyPanel, type FieldType, type FillPdfOptions, type FormField, type PdfBuilder, PdfViewer, type RenderedPage, SIGNER_ROLE_COLORS, SignatureCanvas, SignerRoleSelector, SignerView, type SignerViewProps, type Template, type TextSubtype, type TransformFn, type TransformMap, US_LEGAL, US_LETTER, applyCalibration, createField, createPdfBuilder, downloadPdf, generateFilledPdf, generateId, getSignerColor, postPdfToCallback, renderPdfPages, resolveAllFormulas, resolveFormula, uniqueLabel };
|