> Markdown version of [/magazine/806-generating-odf-files-in-javascript-without-libreoffice](https://www.wearedevelopers.com/magazine/806-generating-odf-files-in-javascript-without-libreoffice). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Generating ODF Files in JavaScript (Without LibreOffice) **By:** Scott Wirth, [Daniel Cranney](https://www.wearedevelopers.com/@daniel-cranney) **Published:** November 28, 2026 You need to generate a `.odt` document from your Node.js app. Perhaps it’s a report, a contract, an invoice. You search npm, and find docx libraries, but they’re not the format you’re looking for. You find LibreOffice headless wrappers, and spin one up: It takes four seconds per document, requires a full LibreOffice installation on your server, crashes under load, and is completely useless in a browser or serverless function. You consider hand-rolling the XML yourself, take a look at the ODF spec, and (most likely) close the tab, and give up. This is the reality for most JavaScript developers who need to generate OpenDocument Format files, and it shouldn’t be this hard. ## Why ODF and why now OpenDocument Format (ODF) is the ISO standard for office documents — the native format of LibreOffice, and the mandated format for public sector software in an increasing number of European countries. Germany’s recent Deutschland-Stack decision requires open standards across public administration. The EU’s Interoperable Europe Act pushes member states toward ODF for document exchange. If you’re building software for European governments, municipalities, or any organisation that cares about digital sovereignty, you will eventually need to produce `.odt` or `.ods` files, there’s almost no way around it. ## Why browser-side generation matters for security There’s a case for generating documents server-side - but there’s a stronger case for not doing it at all. Every time a user’s data travels to your server to be assembled into a document, you’re exposing this data to potential attackers. For healthcare apps, legal tools, HR software, or anything touching GDPR-sensitive data, browser-side document generation is the more defensible architecture: the document is assembled locally, on the user’s machine, and never leaves it. Of course, this is only possible if your document library runs in the browser, and the problem is, most don’t. ![Some simple code in a block passing through a ODF-Kit block to show it being processed, and then resulting in a doc on the right-hand side](https://wearedevelopers.imgix.net//magazine/articles/806/images/content/nU9vkSo09uzJMFRiZtjT-1794560003.gif) ## Why ODF is harder than it looks An `.odt` file is a ZIP archive containing several XML files: `content.xml` for the document body, `styles.xml` for page layout and named styles, `settings.xml` for view settings, `meta.xml` for metadata, and `META-INF/manifest.xml` declaring every file in the archive. Each XML file uses a precise set of namespaces. Miss one and LibreOffice silently ignores the entire section. Get the whitespace wrong in `settings.xml` and freeze panes stop working. Use the wrong anchor type on an image and it renders in the wrong position. “Opens in LibreOffice” is not the same as “valid ODF” — the OASIS ODF validator will find issues that LibreOffice happily ignores, and other applications won’t be so forgiving. Most JavaScript libraries that claim ODF support produce files that pass the smell test but fail on edge cases. The only way to know is to run every generated file through the official OASIS validator — which is what odf-kit does on every CI build. ## odf-kit in practice [odf-kit](https://github.com/GitHubNewbie0/odf-kit) is an Apache 2.0 TypeScript/JavaScript library for generating, filling, reading, and converting ODF files. It has one runtime dependency (fflate, for ZIP), runs in Node.js and browsers, and every output file is validated against the OASIS ODF spec in CI. Here’s an example of how you could use odf-kit to programmatically create a document, complete with formatting and a simple save at the end: **Generating a report:** import { OdtDocument } from "odf-kit"; const doc = new OdtDocument(); doc.addHeading("Q4 Results", 1); doc.addParagraph("Revenue exceeded expectations across all regions."); doc.addTable( [ ["Region", "Revenue", "Growth"], ["North", "$2.1M", "+12%"], ], { border: "0.5pt solid #000" } ); const bytes = await doc.save(); You can also convert an existing HTML document to ODT using `htmlToOdt`: import { htmlToOdt } from "odf-kit"; const bytes = await htmlToOdt(html, { pageFormat: "A4" }); It’s also really straight-forward to use a document as a template, and then pass in different dynamic values to use within it. For example, in our template file (`invoice-template.odt` stored in our `template` variable) we’ll include some placeholders like `{name}`, `{company.address}` and some others, and then : import { fillTemplate } from "odf-kit"; import { readFileSync, writeFileSync } from "fs"; const template = readFileSync("invoice-template.odt"); const result = fillTemplate(template, { name: "Alice", date: "2026-04-22", company: { name: "Acme Corp", address: "123 Main St, Springfield", }, }); writeFileSync("invoice-001.odt", result); ## The warts Odf-kit is a great library, but it’s not all smooth-sailing, and I learned a few lessons along the way: - **LibreOffice requires `xmlns:ooo` on `settings.xml`** - without it, view settings (zoom level, freeze panes, active sheet) are silently ignored, so it’s worth looking out for this early on. - **Whitespace in settings XML matters** - text nodes between config elements cause LibreOffice to discard the entire settings block. You need to compact the XML before writing it, and it’s worth using [one of the many online tools available for this purpose](https://jsonformatter.org/xml-minify). - **Image anchoring is fiddly** - inline images need `anchor: "as-character"`, or they’ll display with line breaks before and afterwards. Much like working with images in Office, Sheets, Pages (and so on), images be a little temperamental, so be prepared to tweak this aspect quite a lot until you get used to it. - **The ODF validator is your friend** — run it in CI. It catches issues that LibreOffice ignores but other applications don’t, so it’s always worth running. ## Where this fits odf-kit is particularly useful for Nextcloud app development (where ODT export is a long-standing open request), for web-based editors using Lexical, TipTap or ProseMirror, and for any European public sector software that needs to produce ODF output without a LibreOffice dependency. The broader point here is that open document standards deserve open source tooling that actually works. The JavaScript ecosystem has had excellent libraries for PDF, DOCX, and XLSX for years and _finally_ ODT is catching up. ## Related Articles - [Generating ODF Files in JavaScript — Without LibreOffice](https://www.wearedevelopers.com/magazine/752-generating-odf-files-in-javascript-without-libreoffice) - [Dev Digest 131 - AI'm not sure about OSS](https://www.wearedevelopers.com/magazine/472-dev-digest-131-ai-m-not-sure-about-oss) - [3 JavaScript-Free Techniques for Accordions, Dialogs, and Table of Contents](https://www.wearedevelopers.com/magazine/684-3-javascript-free-techniques-for-accordions-dialogs-and-table-of-contents) - [Dev Digest 136 - No JS(on) of mine](https://www.wearedevelopers.com/magazine/482-dev-digest-136-no-js-on-of-mine) ## Related Videos - [Why Is Software Documentation Still Static – And Why Modern Browsers Deserve Better](https://www.wearedevelopers.com/videos/2054-why-is-software-documentation-still-static-and-why-modern-browsers-deserve-better) - [New Browser APIs, End of React Create App, Smuggling Data in Emoji and more with Rowdy Rabouw](https://www.wearedevelopers.com/videos/1299-new-browser-apis-end-of-react-create-app-smuggling-data-in-emoji-and-more-with-rowdy-rabouw) - [Open sourcing a library: how hard can that be?](https://www.wearedevelopers.com/videos/1058-open-sourcing-a-library-how-hard-can-that-be) - [WeAreDevelopers LIVE - CSS or BS?](https://www.wearedevelopers.com/videos/1850-wearedevelopers-live-css-or-bs) ## Related Jobs - [Senior Full-Stack Engineer / Technical Lead (Remote)](https://www.wearedevelopers.com/jobs/48609-senior-full-stack-engineer-technical-lead-remote) at **OJOO Limited** - [Fullstack Engineer, Retail Media / AdTech (m/f/d)](https://www.wearedevelopers.com/jobs/48608-fullstack-engineer-retail-media-adtech-m-f-d) at **Redcare Pharmacy** - [Senior Software Engineer - Semantic Data Lake (Open)SDE3](https://www.wearedevelopers.com/jobs/48597-senior-software-engineer-semantic-data-lake-open-sde3) at **WEX** - [Principal Software Engineer, Front End Web UI Platform](https://www.wearedevelopers.com/jobs/ext/4835126-principal-software-engineer-front-end-web-ui-platform) at **GitHub** - [Senior Frontend Developer (Angular)](https://www.wearedevelopers.com/jobs/ext/4887683-senior-frontend-developer-angular) at **Raiffeisen Bank International AG** - [Senior Software Engineer, Identity Platform](https://www.wearedevelopers.com/jobs/ext/4636914-senior-software-engineer-identity-platform) at **GitHub**