@formepdf/resend
v0.7.10
Published
Render a PDF and email it in one call — Forme + Resend
Readme
@formepdf/resend
Render a PDF and email it in one call. Uses Forme for PDF generation and Resend for delivery.
Install
npm install @formepdf/resend resend @formepdf/react @formepdf/coreQuick Start
import { renderDocument } from '@formepdf/core';
import { sendPdf } from '@formepdf/resend';
import { MyInvoice } from './templates/invoice';
// Render the PDF first — works in plain .ts files
const pdfBytes = await renderDocument(MyInvoice({ customer, items }));
// Then email it
const { data, error } = await sendPdf({
resendApiKey: process.env.RESEND_API_KEY,
from: 'Acme Corp <[email protected]>',
to: customer.email,
subject: 'Invoice #001',
pdf: pdfBytes,
filename: 'invoice-001.pdf',
});Generate the PDF separately, email it with sendPdf. You control the rendering, and the same bytes can go to email + storage + whatever else. Returns Resend's { data, error } directly.
Render Callback
For one-liners in .tsx files:
import { sendPdf } from '@formepdf/resend';
import { MyTemplate } from './my-template';
const { data, error } = await sendPdf({
resendApiKey: process.env.RESEND_API_KEY,
from: '[email protected]',
to: '[email protected]',
subject: 'Your document',
render: () => MyTemplate({ name: 'Jane' }),
});Built-in Templates
Skip the render step and use a built-in template:
import { sendPdf } from '@formepdf/resend';
const { data, error } = await sendPdf({
resendApiKey: process.env.RESEND_API_KEY,
from: 'Acme Corp <[email protected]>',
to: '[email protected]',
subject: 'Invoice #001',
template: 'invoice',
data: {
invoiceNumber: 'INV-001',
date: 'February 25, 2026',
dueDate: 'March 27, 2026',
company: { name: 'Acme Corp', initials: 'AC', address: '123 Main St', cityStateZip: 'San Francisco, CA 94105', email: '[email protected]' },
billTo: { name: 'Jane Smith', company: 'Smith Co', address: '456 Oak Ave', cityStateZip: 'Portland, OR 97201', email: '[email protected]' },
shipTo: { name: 'Jane Smith', address: '456 Oak Ave', cityStateZip: 'Portland, OR 97201' },
items: [
{ description: 'Consulting', quantity: 10, unitPrice: 150 },
],
taxRate: 0.08,
paymentTerms: 'Net 30',
},
});Add PDF to an Existing Resend Call
import { renderAndAttach } from '@formepdf/resend';
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
const pdf = await renderAndAttach({ template: 'invoice', data: invoiceData });
await resend.emails.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Your invoice',
html: '<p>See attached.</p>',
attachments: [pdf],
});renderAndAttach returns { filename, content } which is exactly what Resend's attachment API expects.
API
sendPdf(options)
Render a PDF and email it. Returns Resend's { data, error } shape directly.
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| resendApiKey | string | Yes | Resend API key |
| from | string | Yes | Sender address |
| to | string \| string[] | Yes | Recipient(s) |
| subject | string | Yes | Email subject |
| pdf | Uint8Array | One of pdf/render/template | Pre-rendered PDF bytes |
| render | () => ReactElement | One of pdf/render/template | Render callback |
| template | string | One of pdf/render/template | Built-in template name |
| data | object | With template | Data for the template |
| filename | string | No | PDF filename (default: {template}.pdf) |
| html | string | No | Email body HTML |
| text | string | No | Email body plain text |
| react | ReactElement | No | React Email component for email body |
| cc | string \| string[] | No | CC recipients |
| bcc | string \| string[] | No | BCC recipients |
| replyTo | string | No | Reply-to address |
When html, text, and react are all omitted, a default email body is generated based on the template type.
renderAndAttach(options)
Render a PDF and return a Resend-compatible attachment object. Does not send.
listTemplates()
Returns available built-in templates with descriptions.
Built-in Templates
| Template | Description |
|----------|-------------|
| invoice | Line items, tax, totals, company/customer info |
| receipt | Payment confirmation, items, total, payment method |
| report | Multi-section document with title, headings, body text |
| letter | Business letter with letterhead, date, recipient, body |
| shipping-label | From/to addresses, 4x6 label format |
