PDFNet.Convert.toPdfWithBuffer Segfault In AWS Lambda

Product: pdftron/pdfnet-node

Product Version: 9.0.0-3

Please give a brief summary of your issue:
PDFNet.Convert.toPdfWithBuffer segfaults in AWS lambda function but runs fine locally.

Please describe your issue and provide steps to reproduce it:
Utilizing pdftron PDFNet.Convert.toPdfWithBuffer to merge PDF email attachments from MSFT outlook into one PDF. This works fine on MAC OS/Unix however every time I attempt to run this is a lambda function on AWS. A segfault occurs on the toPdfWithBuffer function and I have not been able to figure out why. No error is thrown.

This is my function call: await PDFNet.Convert.toPdfWithBuffer(tempDoc, a[‘content’], ext);

a[content] is the buffer of an email attachment object from microsoft graph client.

and the parameters are as follows:
tempDoc ===> { name: ‘PDFDoc’, id: ‘55ee36fb6d70’ } - created with const tempDoc = await PDFNet.PDFDoc.create();
a[content] ===> <Buffer 25 50 44 46 2d 31 2e 37 0d 25 e2 e3 cf d3 0d 0a 32 34 37 20 30 20 6f 62 6a 0d 3c 3c 2f 4c 69 6e 65 61 72 69 7a 65 64 20 31 2f 4c 20 31 36 35 30 36 38 … 1650638 more bytes>
ext ===> pdf

Has anyone ran into issues utilizing buffers in node on AWS Lambda.

Node version is 14.1.0

What is the exact AWS lambda linux distro you are running?
See supported OS here:

Node JS 14 - 2.880.0 JS SDK - Amazon Linux 2 OS

Linux kernel – 4.14.165-102.205.amzn2.x86_64

Thank you for the clarification.

Could you also provide your full code (or at least the code using our API’s) so we can review.

   const tempDoc = await PDFNet.PDFDoc.create();
   await tempDoc.initSecurityHandler();
          try {
            logger.info('tempDoc ===> ', tempDoc);
            logger.info('a[content] ===> ', a['content']);
            logger.info('ext ===> ', ext);
            await PDFNet.Convert.toPdfWithBuffer(tempDoc, a['content'], ext);
            pageCount = await tempDoc.getPageCount();
            await resultDoc.insertPages(1, tempDoc, 1, pageCount, PDFNet.PDFDoc.InsertFlag.e_none);
          } catch (error) {
            logger.error(JSON.stringify(error, null, 2));
          }

a[‘content’] is a buffer representing an email attachment – either a pdf or a word document – from the microsoft-graph-client api

Thank You,

Are you calling PDFNet.runWithCleanup like here

​runWithCleanup is an important call to make sure the SDK is initialized properly.

https://www.pdftron.com//api/pdfnet-node/PDFNet.html#.runWithCleanup__anchor

If yes, can you confirm that running toPDF, using filepath, works fine or not?

Finally, is the issue file specific?

What if you run our ConvertTest sample?

Hi Ryan,

Thank you for your help, I added the runWithCleanup, we also switched from utilizing the buffer to writing temp files and it appears to be working now.

Previously the issue was not file specific. Since it started working after the aforementioned changes I did not attempt to run the ConvertTest sample.

Thank You,