Unoconv Promise
This is a Node.js wrapper with native Promise support for converting documents with unoconv, inspired by Graham Floyd’s implementation
Setup
Requirement
- Unoconv
- Tested with Unoconv version 0.8.2
- LibreOffice (or OpenOffice.)
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;
});
- Each format will be look like this
{
"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
connection
doctype
export
field
fields
: object contanig user-defined text fields with values to be relaced in the documentformat
(pdf): specify the output formatimport-filter-name
import
listener
no-launch
output
: output basename, filename or directorypassword
pipe
port
printer
preserve
: keep timestamp and permissions of the original documentserver
show
stdout
template
timeout
: timeout after secs if connection to listener failsverbose
version
Extra
bin
(unoconv): Binary commandunoconv
(unoconv): Unoconv custom pathpython
(python): Python custom ptahstring
(false): Return the output as stringfile
(null): Target file
Testing
npm test
- Coverage
npm test:coverage
Supported Formats
bib
bmp
- image/bmpcsv
- text/csvdbf
dif
doc
- application/msworddocx
- application/vnd.openxmlformats-officedocument.wordprocessingml.documentemf
- application/x-msmetafileeps
- application/postscriptfodg
fodp
fods
fodt
gif
- image/gifhtml
- text/htmljpg
- image/jpegltx
met
odd
odg
- application/vnd.oasis.opendocument.graphicsodp
- application/vnd.oasis.opendocument.presentationods
- application/vnd.oasis.opendocument.spreadsheetodt
- application/vnd.oasis.opendocument.textotg
- application/vnd.oasis.opendocument.graphics-templateotp
- application/vnd.oasis.opendocument.presentation-templateots
- application/vnd.oasis.opendocument.spreadsheet-templateott
- application/vnd.oasis.opendocument.text-templatepbm
- image/x-portable-bitmappct
- image/x-pictpdb
- application/vnd.palmpdf
- application/pdfpgm
- image/x-portable-graymappng
- image/pngpot
- application/vnd.ms-powerpointpotm
- application/vnd.ms-powerpoint.template.macroenabled.12ppm
- image/x-portable-pixmappps
- application/vnd.ms-powerpointppt
- application/vnd.ms-powerpointpptx
- application/vnd.openxmlformats-officedocument.presentationml.presentationpsw
pwp
pxl
ras
- image/x-cmu-rasterrtf
- application/rtfsda
- application/vnd.stardivision.drawsdc
- application/vnd.stardivision.calcsdd
- application/vnd.stardivision.impresssdw
- application/vnd.stardivision.writerslk
stc
- application/vnd.sun.xml.calc.templatestd
- application/vnd.sun.xml.draw.templatesti
- application/vnd.sun.xml.impress.templatestw
- application/vnd.sun.xml.writer.templatesvg
- image/svg+xmlsvm
swf
- application/x-shockwave-flashsxc
- application/vnd.sun.xml.calcsxd
- application/vnd.sun.xml.drawsxi
- application/vnd.sun.xml.impresssxw
- application/vnd.sun.xml.writertiff
- image/tifftxt
- text/plainuop
uos
uot
vor
- application/vnd.stardivision.writerwmf
- application/x-msmetafilewps
- application/vnd.ms-worksxhtml
- application/xhtml+xmlxls
- application/vnd.ms-excelxlsx
- application/vnd.openxmlformats-officedocument.spreadsheetml.sheetxlt
- application/vnd.ms-excelxml
- application/xmlxpm
- image/x-xpixmap’