Repository navigation
HTML export support from react-pdf document #3490
Replies: 1 comment
|
Hi! No, react-pdf does not support exporting HTML. The library turns your components into PDF drawing commands, so there is no That said, you can get most of the way there yourself. Internally the pipeline works like this: your JSX gets turned into an element tree, then the layout step resolves it into a plain JS object where every node has its final position, size, styles and text lines. Only after that it gets painted into a PDF. If you run the layout step manually and stop there, you have all the information needed to output HTML with absolutely positioned elements: import layoutDocument from "@react-pdf/layout";
const layoutTree = await layoutDocument(elementTree, fontStore);
// walk layoutTree and emit your own HTML from each node box and styleAn easy way to see what this object looks like is the The part that walks that object and generates the HTML string is something you would need to build yourself, since the library does not provide it. Hope that helps! |
Uh oh!
There was an error while loading. Please reload this page.
Hi, is there a way to generate a static html string from the pdf document jsx, like
pdf(<Document />).toHTMLString()?All reactions