/aws-lambda-libreoffice

85 MB LibreOffice to fit inside AWS Lambda (and Google Cloud Functions) compressed with Brotli

Primary LanguageJavaScriptMIT LicenseMIT

aws-lambda-libreoffice

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)

Install

$ yarn add @shelf/aws-lambda-libreoffice

Usage

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`);

See Also

License

MIT © Shelf