Forma PDF
Integrate a PDF editor with React and Next.js
By WVSTECH · Reviewed November 23, 2026 · Examples target SDK 0.4.0
Forma PDF is a browser SDK. In React, mount the editor after the host element exists and destroy it on unmount. In Next.js, keep the integration in a client component and load browser-dependent code inside the effect.
A client component with lifecycle cleanup
'use client'
import { useEffect, useRef } from 'react'
export default function DocumentEditor({ layout, values }) {
const host = useRef(null)
useEffect(() => {
let disposed = false
let editor
import('./sdk/forma-pdf.js').then(({ createEditor }) => {
if (!disposed && host.current) {
editor = createEditor(host.current, { layout, values, locale: 'en' })
}
})
return () => { disposed = true; editor?.destroy() }
}, [layout, values])
return <div ref={host} style={{ height: '80vh' }} />
}
Keep document state stable
This minimal example remounts when layout or values change. In a larger application, keep stable input objects and use instance methods such as setDocument for intentional updates. Avoid feeding every onChange event back into a remount cycle.
The SDK is delivered as compiled files, rather than a public npm dependency. Adapt the import path to your bundle and include the provided stylesheet. Your server can store templates and authorize data access; the browser generates the PDF. See the SDK setup guide for package contents.
Continue building
- Add PDF templates to a Bolt or Lovable project
- Generate a PDF from JSON in the browser
- Embed a visual PDF template editor in JavaScript
- Save PDF templates as JSON in your database
- Create editable PDF templates in Bubble workflows
- Automatic PDF page breaks for text and tables
- Build a quotation PDF generator for your application
- Create a restaurant menu PDF from structured data
- Generate internal documents and memos from app data
- Generate PDF templates with OpenAI or Claude
- PDF generation, document data and API-key security
- PDF template editor or a simple Generate PDF button?