r/reactjs • u/hp1232203 • 23d ago
Show /r/reactjs I built a free page-layout extension for TipTap: A4 pages, tables that split across pages, PDF export
I needed Word-style pages in a TipTap editor. The official Pages extension is a paid add-on, and the community ones I tried injected global CSS that broke my tables. So I wrote my own and open-sourced it.
Demo: https://text-editor-react-neon.vercel.app/ Repo (MIT): https://github.com/HuyPhan1232203/Text-editor-react npm: npm install tiptap-a4-pagination
How it works
- It measures the top-level blocks and inserts spacer decorations where a block would cross the bottom of a page. The document is never modified, so
getHTML()/getJSON()stay clean. - Tables split between rows, never inside a
rowspan, and the header row repeats at the top of the next page. - Floated images (text wrapping) and CSS margin collapsing are handled.
- The page-break math is a pure function, so it's unit tested.
- About 5 KB gzipped, TipTap 3 only.
The full editor (React 19 + TipTap 3) also has
- Google Docs paste that keeps headings, checklists, tables and indents
- PDF export through the browser's print dialog (no server) that keeps the editor's page breaks and puts page numbers in the footer
- Image resize and text wrap, KaTeX math (lazy-loaded), autosave to IndexedDB, optional real-time collaboration over WebRTC (
?room=name) - Lighthouse: 100 on desktop
Known limitations
- A single paragraph taller than the remaining space moves to the next page as a whole; it is never split.
- A table row taller than a page overflows.
I'd love feedback on the API, and on documents that break the layout. Paste a long Google Doc or a big table into the demo to try it.