Skip to content
Genom

Render a Word document in the browser

Pages broken where Word breaks them — measured, not guessed.

.docx.docOne package, every generation — @genomdev/docx

Loading the viewer…
sample.docxrendered in this tab, nothing uploaded

Word stores a flow of paragraphs, not pages, so where the breaks fall depends on the fonts available and the printable area. Trusting the hints Word cached reproduces the pagination of whichever machine last saved the file; this measures the content as displayed and breaks accordingly, which is the only way the page numbers in a footer can be right.

Switch the tab to `.doc` and nothing about the code changes. The binary reader produces the same model the modern parser does, so the viewer, the extractor and the addressing scheme work on a file from the nineties with nothing anywhere that knows it is one.

import { DocumentViewer } from '@genomdev/react';
import { docx } from '@genomdev/genom/lazy';

// One package covers every generation of a Word document; the reader is
// chosen from the container, not from the file name.
<DocumentViewer file={file} formats={[docx]} fit="width" />;

Put it in your own application

What is above is the published package running in this page, with nothing behind it. The documentation covers the same ground with the API in full.