Created
June 29, 2019 23:13
-
-
Save sm-a/48fabeede2fdf3c0fcb13f726761482e to your computer and use it in GitHub Desktop.
This file contains 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
[...] | |
docx.init({ | |
ND_DEV_ID: "", // goto https://developers.nativedocuments.com/ to get a dev-id/dev-secret | |
ND_DEV_SECRET: "", // you can also set the credentials in the enviroment variables | |
ENVIRONMENT: "NODE", // required | |
LAZY_INIT: true // if set to false the WASM engine will be initialized right now, usefull pre-caching (like e.g. for AWS lambda) | |
}).catch(function (e) { | |
console.error(e); | |
}); | |
async function convertHelper(document, exportFct) { | |
const api = await docx.engine(); | |
await api.load(document); | |
const arrayBuffer = await api[exportFct](); | |
await api.close(); | |
return arrayBuffer; | |
} | |
router.get("/", function (req, res) { | |
const params = { Bucket: 'mybucket', Key: 'test.docx' }; | |
s3.getObject(params, function (err, data) { | |
if (err) console.log(err, err.stack); // an error occurred | |
else { | |
convertHelper(new Uint8Array(data), "exportPDF").then((arrayBuffer) => { | |
fs.writeFileSync("out.pdf", new Uint8Array(arrayBuffer)); | |
res.send("OK"); | |
}).catch((e) => { | |
console.error(e); | |
res.send("ERROR: " + e) | |
}); | |
}; // successful response | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment