DEV Community

Cover image for I Built a TypeScript Library for Generating ODF Documents — Here's Why the JS Ecosystem Needed One
Dev.to Newbie
Dev.to Newbie

Posted on

I Built a TypeScript Library for Generating ODF Documents — Here's Why the JS Ecosystem Needed One

If you've ever needed to generate Word-compatible documents in Node.js, you've probably reached for docx or pdfkit. But what if your users need OpenDocument Format — the ISO standard used by LibreOffice, government agencies, and organizations that can't depend on proprietary formats?
Until now, your options in JavaScript were basically: nothing.
The only prior library, simple-odf, was abandoned in 2021. It only produced flat XML files (not proper .odt ZIP packages) and had no table support. Meanwhile, the Java ecosystem has the full-featured Apache ODF Toolkit, Python has odfpy, and C# has options too. JavaScript developers were left out.
So I built odf-kit.
What It Does
odf-kit is a TypeScript library that generates valid .odt files — proper ZIP-packaged ODF documents that open cleanly in LibreOffice, Google Docs, and any ODF-compliant application. Single runtime dependency (JSZip), ESM-only, Node 22+.
Here's what it takes to create a document:
typescriptimport { OdtDocument } from "odf-kit";

const doc = new OdtDocument();
doc.setMetadata({ title: "Quarterly Report", creator: "odf-kit" });
doc.addHeading("Summary", 1);
doc.addParagraph("Generated with odf-kit.");
doc.addTable([
["Metric", "Q1", "Q2"],
["Revenue", "$1.2M", "$1.5M"],
], { columnWidths: ["5cm", "3cm", "3cm"], border: "0.5pt solid #000000" });

const bytes = await doc.save();
What's Supported (v0.1.0)

Text formatting (bold, italic, underline, strikethrough, font size/family/color, subscript, superscript, highlight)
Tables with column widths, cell borders, background colors, and cell merging
Bullet and numbered lists with nesting up to 6 levels
Page layout (size, margins, orientation)
Headers and footers with page numbers
Page breaks
Hyperlinks and bookmarks
Embedded images (PNG, JPEG, GIF, SVG, WebP, BMP, TIFF)
Tab stops

All covered by 102 tests, validated against LibreOffice 24.2.
Who Is This For?
Anyone building tools for organizations that need open formats — non-profits, government agencies, educational institutions, or any project where depending on Microsoft's .docx format isn't an option. ODF is an ISO standard (ISO/IEC 26300), and several countries mandate its use in public sector IT.
If you've been generating .docx files simply because there was no ODF alternative in JavaScript, now there is.
Links

npm: npmjs.com/package/odf-kit
GitHub: github.com/GitHubNewbie0/odf-kit
Landing page: githubnewbie0.github.io/odf-kit
License: Apache 2.0

I'd love feedback — especially on the API design. The goal was to make the common case dead simple while keeping complex formatting available for those who need it.

Top comments (0)