@matbee/libreoffice-converter
v2.1.0
Published
LibreOffice WASM document conversion toolkit - headless document format conversion
Downloads
2,684
Maintainers
Readme
LibreOffice WASM Document Converter
Convert documents between formats (DOCX, PDF, XLSX, PPTX, etc.) in Node.js or browsers using LibreOffice compiled to WebAssembly. No native dependencies required.
Features
- Pure WebAssembly - No native LibreOffice installation required
- Wide Format Support - Convert between 15+ document formats
- Cross-Platform - Works in Node.js and browsers
- Fast - ~35ms per conversion after initialization
Installation
npm install @matbee/libreoffice-converterDemo
https://convertmydocuments.com
Quick Start
One-Shot Conversion (Simplest)
import { convertDocument } from '@matbee/libreoffice-converter';
import fs from 'fs';
const docx = fs.readFileSync('document.docx');
const result = await convertDocument(docx, { outputFormat: 'pdf' });
fs.writeFileSync('document.pdf', result.data);Export as Image
import { exportAsImage } from '@matbee/libreoffice-converter';
import fs from 'fs';
// Export single page (0-indexed)
const [cover] = await exportAsImage(docxBuffer, 0, 'png');
fs.writeFileSync('cover.png', cover.data);
// Export multiple pages
const slides = await exportAsImage(pptxBuffer, [0, 1, 2], 'png');
slides.forEach((img, i) => fs.writeFileSync(`slide-${i}.png`, img.data));
// Export with options
const highRes = await exportAsImage(pptxBuffer, [0, 1, 2], 'png', { dpi: 300, width: 1920 });Server Usage (Recommended)
For servers, use the worker converter to avoid blocking the main thread:
import { createWorkerConverter } from '@matbee/libreoffice-converter';
const converter = await createWorkerConverter({ wasmPath: './wasm' });
// Reuse for multiple conversions
const pdf = await converter.convert(docxBuffer, { outputFormat: 'pdf' });
const csv = await converter.convert(xlsxBuffer, { outputFormat: 'csv' });
await converter.destroy(); // Clean up when doneSupported Formats
Input: doc, docx, xls, xlsx, ppt, pptx, odt, ods, odp, rtf, txt, html, csv, pdf, epub
Output: pdf, docx, doc, odt, rtf, txt, html, xlsx, xls, ods, csv, pptx, ppt, odp, png, jpg, svg
Browser Usage
import { WorkerBrowserConverter, createWasmPaths } from '@matbee/libreoffice-converter/browser';
const converter = new WorkerBrowserConverter({
...createWasmPaths('/wasm/'),
browserWorkerJs: '/dist/browser.worker.js',
onProgress: (info) => console.log(`${info.percent}%: ${info.message}`),
});
await converter.initialize();
const result = await converter.convert(fileData, { outputFormat: 'pdf' }, 'doc.docx');
// Download result
const blob = new Blob([result.data], { type: result.mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = result.filename;
a.click();Required HTTP headers for SharedArrayBuffer:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corpDocumentation
- API Reference - Complete API documentation, types, configuration options
- Examples - Express server, React component, batch conversion, and more
System Requirements
- Node.js 18.0.0+
- ~150MB disk space for WASM files
- Browser: ~240MB initial download (cached after first load)
License
MPL-2.0 (same as LibreOffice)
Contributing
git clone https://github.com/matbeedotcom/libreoffice-document-converter.git
cd libreoffice-document-converter
npm install
npm run build
npm testSee docs/API.md#building-from-source for building the WASM module.
