LibreOffice WASM document conversion toolkit - headless document format conversion
npm install @matbee/libreoffice-converterConvert documents between formats (DOCX, PDF, XLSX, PPTX, etc.) in Node.js or browsers using LibreOffice compiled to WebAssembly. No native dependencies required.
- 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
``bash`
npm install @matbee/libreoffice-converter
`javascript
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);
`
`javascript
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 });
`
For servers, use the worker converter to avoid blocking the main thread:
`javascript
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 done
`
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
`javascript
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-corp
- API Reference - Complete API documentation, types, configuration options
- Examples - Express server, React component, batch conversion, and more
- Node.js 18.0.0+
- ~150MB disk space for WASM files
- Browser: ~240MB initial download (cached after first load)
MPL-2.0 (same as LibreOffice)
`bash``
git clone https://github.com/matbeedotcom/libreoffice-document-converter.git
cd libreoffice-document-converter
npm install
npm run build
npm test
See docs/API.md#building-from-source for building the WASM module.