Last active
June 2, 2016 18:06
-
-
Save threeaccents/fb549371dce23c15c85598064bfd708e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const spawnSync = require('child_process').spawnSync; | |
const defaultDestPath = __dirname + '/pdf'; | |
function convertToPdf(filepath, destpath) { | |
var resp = {}; | |
if (destpath == undefined) { | |
destpath = defaultDestPath; | |
} | |
var cmd = 'soffice'; | |
var args = ['--headless', '"-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"', '--convert-to', 'pdf:writer_pdf_Export', filepath, '--outdir', destpath] | |
var spawn = spawnSync(cmd, args); | |
var resp = {}; | |
if (spawn.error != undefined || spawn.stderr.toString() != '') { | |
if (spawn.error != undefined) { | |
resp.error = spawn.error.code; | |
resp.destpath = null; | |
} | |
if (spawn.stderr.toString() != '' != null) { | |
resp.stderr = spawn.stderr.toString(); | |
resp.destpath = destpath; | |
} | |
} else if (spawn.stdout) { | |
resp.error = null; | |
resp.destpath = destpath; | |
} | |
return resp; | |
} | |
var res = convertToPdf("test.doc"); | |
console.log(res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment