Change a customer name, add a line item, then choose Download. The PDF should contain the latest details. A live preview editor has to keep that promise even when someone edits quickly, cancels a render, or closes the form.
The Fullbleed React starter connects a form to a styled invoice, an actual PDF preview, and a download. Its default document uses typed JSX components for the rows, totals, and payment status. The usePdfPreview hook keeps the result tied to the current inputs. Rendering runs in a Web Worker, and document inputs stay in this browser.

Start with a running document
Open the editor, expand Edit line items, and change a quantity or rate. Check Paid in full to change the payment text. Wait for Ready, then choose Download PDF. The form supports up to 20 rows, whole hours, and negative rates for credits; it calculates amounts in integer cents.
To change the document itself, choose Edit the project online, then Open in StackBlitz. The source editor opens src/documents/Invoice.tsx. Change a heading there, or a print rule in src/documents/invoiceStyles.ts. Save or export the project to keep your work.
For local development, extract the ZIP and open a terminal in fullbleed-react-starter. Use Node.js 22.13 or newer on the 22.x line, or Node.js 23.5 or newer, including 24.x:
npm ci
npm run dev
Open the localhost address printed by Vite. This project's lockfile pins Fullbleed npm 0.8.3, engine 2.5.38, and React 19.3.0. Keep the lockfile and package overrides when adapting the starter. The project is MIT licensed, including commercial use.
Compose the print document with typed components
src/App.tsx uses React for the interactive application. The print file starts with /** @jsxImportSource fullbleed/ui */ to select Fullbleed's JSX runtime for that file. Its functions compose a static document; use React hooks and fetch application data in the surrounding React app.
For example, this total component takes the relevant parts of InvoiceData, sums the rows, and changes its text when the invoice is paid. This is an excerpt from the complete invoice source:
function Total({ items, due, paid }: Pick<InvoiceData, 'items' | 'due' | 'paid'>) {
return <Section className="total" aria-label="Invoice total">
<Text className="label">{paid ? 'Paid in full' : 'Amount due · USD'}</Text>
<Paragraph className="total-amount">{money(items.reduce((sum, item) => sum + item.quantity * item.rate_cents, 0))}</Paragraph>
<Paragraph className="total-note">{paid ? 'Thank you.' : `Due ${due}`}</Paragraph>
</Section>;
}
The same file maps typed items into WorkRow components and composes reusable fields, a work table, and payment notes. src/documents/data.ts contains the data model, sample records, validation, and money formatting. In the app, Invoice({ data, ink }) composes the document passed to the preview hook.
Connect className to the document stylesheet
className="total" selects the '.total' rule in src/documents/invoiceStyles.ts. That rule supplies the background, text color, padding, and corner radius. The invoice then composes the base sheet with the chosen ink color:
const styles = new StyleSheet(invoiceStyles, {
body: { color: ink }, '.brand': { borderBottomColor: ink },
th: { borderTopColor: ink, borderBottomColor: ink },
'.note strong': { color: ink }, '.total': { background: ink },
});
The enclosing <Document title="Northstar Studio / Invoice" lang="en" styles={styles}> attaches that stylesheet. The class name identifies the element; the attached sheet supplies its appearance. Rules in src/style.css style the React interface. Put print rules in the document stylesheet so they reach the PDF.
See the component styling guide for selectors, composed sheets, and inline styles. The HTML/CSS invoice and Community report choices remain available in the design selector. Choose either to use Edit the HTML & CSS; keep lasting edits in the corresponding src/invoice.* or src/report.* files.
Keep the download tied to the current inputs
A completed PDF belongs to the inputs that produced it. The hook records both the input object and runtime asset URL with each result. During a React render, it exposes that result only while both still match:
const visible: State = state.input === input && state.assetBaseUrl === assetBaseUrl
? state : { input, assetBaseUrl, status: auto && input !== null ? 'queued' : 'idle' };
return { ...visible, generate, cancel };
The app memoizes its input with useMemo, so unrelated renders do not look like document edits. The default 450 ms delay reduces work during a burst of typing. Debouncing alone cannot stop an older job from finishing after a newer request.
Each render also gets a serial number. Invalidating a request increments that number and aborts its controller. The hook accepts either a composed document or HTML/CSS, then checks the identity before creating any download or preview URLs:
const renderer = createRenderer({ assetBaseUrl });
let rendered: BrowserRenderResult;
if ('document' in input) {
const { document, ...options } = input;
rendered = await renderDocument(document, renderer, { ...options, signal: controller.signal });
} else {
rendered = await renderer.renderPdf({ ...input, signal: controller.signal });
}
// An aborted or superseded request must never replace a newer document.
if (!current.mounted || serial !== current.serial) return;
Cancellation stops obsolete work; the serial check decides whether a result still belongs on screen. The hook checks errors in the same way. The complete hook includes invalid-input handling and manual generation.
Release preview resources when the editor changes
Every ready document creates a PDF Blob URL and one PNG Blob URL per preview page. The hook releases them when inputs change, Cancel is pressed, or the editor unmounts. Its shared cleanup also clears the timer and aborts active work:
current.serial += 1;
clearTimeout(current.timer);
current.timer = undefined;
current.controller?.abort();
current.controller = null;
current.urls.forEach(url => URL.revokeObjectURL(url));
current.urls = [];
The starter enables React Strict Mode. Its extra development setup and cleanup cycle helps exercise reopening the editor. React's Effect cleanup guidance explains this lifecycle.
Try these behaviors before adapting the hook:
- Change the customer name twice. The old download disappears until the latest PDF is ready.
- Edit a field and choose Cancel before the preview starts. Edit again or choose Generate PDF to continue.
- Turn off Update automatically. Edits now wait for Generate PDF.
- Choose Close editor, then reopen it. The editor starts with the default document; save lasting changes in the source project.
For an existing React app, follow the focused preview and download recipe or the integration guide. Deploy the worker, engine, fonts, and notices together. The first preview downloads runtime assets; the built app can run on a static HTTPS host without a PDF server.
Fullbleed lays out a static print document using its supported HTML/CSS. It does not capture the surrounding React interface. This browser entry produces ordinary PDFs and PNG previews. Check the document-profile guidance for tagged or archival output requirements.
Checked against the downloadable source. The code excerpts above come from the 0.8.3 React starter ZIP. The retained starter verification records the package and source hashes and the generated PDF checks. The React starter checks cover Chrome, Firefox, Playwright WebKit, and the React development workflow. These fixtures do not establish compatibility with every browser, document, or device.