Next up World Congress Europe Jul 14–16, 2027 · Berlin Find out more
SW
Scott Wirth
DC
Daniel Cranney

Generating ODF Files in JavaScript (Without LibreOffice)

November 28, 2026
Some JavaScript code being passed to odf-kit and then resulting in a document
Some JavaScript code being passed to odf-kit and then resulting in a document

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

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 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.
  • 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.