An Effect-based wrapper for document conversion using LibreOffice compiled to WebAssembly.
Starting with version 2.x.x, effect-libreoffice executes conversions directly within your Node.js application using @matbee/libreoffice-converter. It requires no local installation of LibreOffice and no external servers, making it highly portable and easy to use.
Install the library along with its peer dependencies:
pnpm add effect-libreoffice effect@rc @effect/platform-node@rcYou must also install the WebAssembly converter package:
pnpm add @matbee/libreoffice-converterimport { NodeServices } from "@effect/platform-node";
import { Effect, FileSystem, Layer } from "effect";
import { LibreOffice } from "effect-libreoffice";
import { LibreOfficeNode } from "effect-libreoffice/node";
const program = Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const libre = yield* LibreOffice.LibreOffice;
// Read the input document into a Uint8Array
const inputData = yield* fs.readFile("input.docx");
// Convert it using the LibreOffice engine
const result = yield* libre.convert(inputData, {
inputFormat: "docx",
outputFormat: "pdf",
});
// Write the resulting Uint8Array to disk
yield* fs.writeFile("output.pdf", result.data);
// You can also access other document utilities:
const pageCount = yield* libre.getPageCount(inputData, {
inputFormat: "docx",
});
console.log(`The document has ${pageCount} pages.`);
});
const MainLayer = Layer.mergeAll(LibreOfficeNode.layer, NodeServices.layer);
program.pipe(Effect.provide(MainLayer), Effect.runPromise);The LibreOffice.LibreOffice service exposes the following WASM-based operations:
convert: Convert documents to a different formatgetPageCount: Get the number of pages/parts in a documentgetDocumentInfo: Get document type and valid output formatsrenderPage: Render a single page as an imagerenderPagePreviews: Render multiple page previewsrenderPageFullQuality: Render a page at full quality nativelygetDocumentText: Extract text content from a documentgetPageNames: Get page or slide names from a document