
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
node-unoconv
Advanced tools
Lightweight NodeJS wrapper for unoconv, a Universal Office Converter.
The node-unoconv package requires unoconv and its dependencies to be installed.
Office software is required to run unoconv. LibreOffice is recommended but OpenOffice is still supported.
Please see official installation instructions on the LibreOffice website.
https://www.libreoffice.org/get-help/install-howto/
Use command below to install LibreOffice inside Docker container:
RUN apt-get -y install libreoffice
Please see official installation instructions on the OpenOffice website.
https://www.openoffice.org/download/common/instructions.html
After you install required dependencies, the node-unoconv package can be installed using commands below:
npm install node-unoconv
# or using yarn
yarn add node-unoconv
There are few ways to import node-unoconv package to your NodeJS project:
// ES6 import
import unoconv from 'node-unoconv';
unoconv.convert(input, options?); // Converting a file
unoconv.listen(options?); // Starting a conversion listener
// Using named exports
import { convert, listen } from 'node-unoconv';
convert(input, options?); // Converting a file
listen(options?); // Starting a conversion listener
// Using Require
const unoconv = require('node-unoconv');
unoconv.convert(input, options?); // Converting a file
unoconv.listen(options?); // Starting a conversion listener
// Alternative way to require convert or listen methods
const { convert, listen } = require('node-unoconv');
convert(input, options?); // Converting a file
listen(options?); // Starting a conversion listener
Converts an input file to a format specified in options object (defaults to pdf). By default, a promise is returned that resolves with a buffer or rejects with an error message. A callback function is also supported.
// Convert a file using a promise
unoconv.convert('file.doc')
.then((buffer) => {
console.log(buffer.length);
}.catch((err) => {
console.error(err);
});
// or with async/await
const buffer = await unoconv.convert('file.doc');
Conversion with an output path and a callback
const callback = (path, error) => {
if (error) {
console.error('Error', error);
return;
}
console.log('Path:', path);
};
const options = {
callback,
output: 'file.pdf'
};
unoconv.convert(path);
Starts a standalone LibreOffice or OpenOffice listener.
If server or port options are not specified, it uses defaults values 127.0.0.1 and 2002.
unoconv.listen();
const options = {
port: 2003,
server: '127.0.0.1'
};
unoconv.listen(options);
Option | Type | Default | Description |
---|---|---|---|
connection | string | UNO connection string to be used by the client to connect to an LibreOffice instance, or used by the listener to make LibreOffice listen. | |
output | string | file.pdf | Output basename, filename or directory. |
doctype | string | document | Specify the LibreOffice document type of the backend format. Possible document types are: document, graphics, presentation, spreadsheet. |
password | string | Provide a password to decrypt the document. | |
server | string | 127.0.0.1 | Server (address) to listen on (as listener) or to connect to (as client). |
port | number | 2002 | Port to listen on (as listener) or to connect to (as client). |
pipe | Use a pipe as an alternative connection mechanism to talk to LibreOffice. | ||
export | string[] | Set specific export filter options (related to the used LibreOffice filter). | |
field | string[] | Replace user-defined text field with value. | |
format | string | pdf | Specify the output format for the document. You can get a list of possible output formats per document type by using the --show option. Default document type is 'pdf'. |
import | string | utf-8 | Set specific import filters options (related to the used LibreOffice import filter based on the input filename). |
inputFilterName | string | xml | Set input filter name, useful when converting stdin or files without an extension. |
listener | bool | false | Start unoconv as listener for unoconv clients to connect to. It's recommended to start the listener with listen() method. |
disableHtmlUpdateLinks | bool | false | Disables the recheck for updating links missed by libreoffice |
noLaunch | bool | false | By default if no listener is running, unoconv will launch its own (temporary) listener to make sure the conversion works. This option will abort the conversion if no listener is found, rather than starting our own listener. |
preserve | bool | false | Keep timestamp and permissions of the original document. |
printer | string[] | Printer options - PaperFormat: specify printer paper format, eg. PaperFormat=A3 - PaperOrientation: specify printer paper orientation, eg. PaperOrientation=landscape - PapserSize: specify printer paper size, paper format should set to USER, size=widthxheight, e.g. eg. PaperSize=130x200 means width=130, height=200 |
Multiple values can be passed to an option as an array or as an object literal. See the example below, both ways result in the same command arguments passed to unoconv.
const options = {
printer: ['PaperFormat=A3', 'PaperOrientation=landscape'],
};
// or
const options = {
printer: {
PaperFormat: 'A3',
PaperOrientation: 'landscape',
},
};
const options = {
connection: 'socket,host=localhost,port=2002;urp;StarOffice.ComponentContext',
output: 'PDF',
doctype: 'document',
password: 'Abc123!@#',
server: '127.0.0.1',
port: 2002,
export: { PageRange: '1-2' },
field: { foo: 'bar' },
format: 'PDF',
import: { Quality: 50 },
inputFilterName: 'odt',
disableHtmlUpdateLinks: false,
noLaunch: true,
preserve: true,
printer: ['PaperFormat=A3', 'PaperOrientation=landscape'],
}
{
connection: '-c',
disableHtmlUpdateLinks: '--disable-html-update-links',
doctype: '-d',
export: '-e',
field: '-F',
format: '-f',
import: '-i',
importFilterName: '-I',
listener: '-l',
noLaunch: '-n',
output: '-o',
password: '--password',
pipe: '--pipe',
port: '-p',
preserve: '--preserve',
printer: '--printer',
server: '--server',
show: '--show',
stdin: '--stdin',
stdout: '--stdout',
template: '-t',
timeout: '-T',
unsafeQuietUpdate: '--unsafe-quiet-update',
userProfile: '--user-profile',
verbose: '--verbose',
};
Package | Size | Last commit | Downloads/mo |
---|---|---|---|
damian66/node-unoconv | |||
gfloyd/node-unoconv | |||
zxhaaa6/awesome-unoconv | |||
vworld4u/office-converter | |||
ryanhanwu/Unoconv-Promise |
FAQs
Lightweight NodeJS wrapper for unoconv, a Universal Office Converter.
The npm package node-unoconv receives a total of 116 weekly downloads. As such, node-unoconv popularity was classified as not popular.
We found that node-unoconv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.