Unoconv Promise

npm Build Status JS.ORG

This is a Node.js wrapper with native Promise support for converting documents with unoconv, inspired by Graham Floyd’s implementation

Setup

Requirement

Mac Only

With Homebrew

$ brew install unoconv

and in order to use unoconv, a copy of LibreOffice between versions 3.6.0.1 - 4.3.x must be installed.

Installation

$ npm install unoconv-promise

Usage

Basic

Convert document file into PDF and return as a Buffer

const unoconv = require("unoconv-promise");

unoconv
  .convert("./mydoc.doc")
  .then(fileBuffer => {
    // Converted file buffer
    return Promise.resolve(fileBuffer);
  })
  .catch(e => {
    throw e;
  });

Convert document first page to PDF and save to a file

const unoconv = require("unoconv-promise");

unoconv
  .run({
    file: "./mydoc.doc",
    output: "./temp.pdf",
    export: "PageRange=1-1"
  })
  .then(filePath => {
    console.log(filePath);
  })
  .catch(e => {
    throw e;
  });

Show supported formats

const unoconv = require("unoconv-promise");

unoconv
  .formats()
  .then(formats => {
    // formats will be an array contains supports formats
    formats.forEach(format => {
      console.log(format);
    });
  })
  .catch(e => {
    throw e;
  });
{
  "format": "doc",
  "doctype": "document",
  "extension": "doc",
  "description": " Microsoft Word 97/2000/XP",
  "mime": "application/msword"
}

Unoconv.run options

Option (default) : Description

From unoconv Please check unoconv -h more details

Extra

Testing

npm test
npm test:coverage

Supported Formats

Reference