@formepdf/sdk
v0.9.0
Published
TypeScript client for the Forme hosted PDF API
Readme
@formepdf/sdk
TypeScript client for the Forme hosted PDF API.
Installation
npm install @formepdf/sdkQuick start
import { Forme } from '@formepdf/sdk';
const forme = new Forme('your-api-key');
// Render a template to PDF
const pdf = await forme.render('invoice', {
customerName: 'Acme Corp',
items: [{ name: 'Widget', price: 9.99 }],
});
// pdf is a Uint8Array — write to file, return as response, etc.
await fs.writeFile('invoice.pdf', pdf);
// Extract embedded data from a PDF
const data = await forme.extract(pdf);
// data === { customerName: 'Acme Corp', items: [...] }Constructor
new Forme(apiKey: string, options?: { baseUrl?: string })| Option | Default | Description |
| --------- | ---------------------------- | ------------------------ |
| baseUrl | https://api.formepdf.com | API base URL |
Methods
render(slug, data?)
Render a template to PDF bytes.
- slug — Template identifier
- data — Template data (sent as JSON body, defaults to
{}) - Returns
Promise<Uint8Array>
extract(pdf)
Extract embedded data from a PDF generated by Forme.
- pdf — PDF file bytes
- Returns
Promise<unknown | null>—nullif the PDF has no embedded data
Error handling
import { Forme, FormeError } from '@formepdf/sdk';
try {
const pdf = await forme.render('invoice', data);
} catch (err) {
if (err instanceof FormeError) {
console.error(`API error ${err.status}: ${err.message}`);
}
}Requirements
Node.js 18+ (uses global fetch).
