85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli
Inspired by chrome-aws-lambda
✨ Also works in Google Cloud Functions as long as you select Node.js 8 runtime (thanks to ncruces for the info)
$ yarn add @shelf/aws-lambda-libreoffice
const {convertFileToPDF} = require('@shelf/aws-lambda-libreoffice');
module.exports.handler = async () => {
// assuming there is a document.docx file inside /tmp dir
// original file will be deleted afterwards
return convertFileToPDF('/tmp/document.docx'); // will create /tmp/document.pdf
};
Or if you want more control:
const {getExecutablePath, defaultArgs} = require('@shelf/aws-lambda-libreoffice');
const loBinary = await getExecutablePath(); // /tmp/instdir/program/soffice
execSync(`${loBinary} ${defaultArgs.join(' ')} --convert-to pdf file.docx --outdir /tmp`);
MIT © Shelf