Skip to content

Instantly share code, notes, and snippets.

@sm-a
Created June 29, 2019 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sm-a/48fabeede2fdf3c0fcb13f726761482e to your computer and use it in GitHub Desktop.
Save sm-a/48fabeede2fdf3c0fcb13f726761482e to your computer and use it in GitHub Desktop.
[...]
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