question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blank PDF's getting generated for subsequent uploaded document

See original GitHub issue

@shelfio/aws-lambda-libreoffice Version: 3.0.1

Problem: First time when libre lambda function is invoked, it works well giving desired output of pdf however if i submit multiple document for conversion then it generates blank pdf’s.

Code snippet: (handler.js)

module.exports.libre = async event => {
 
   console.log("Incoming Event: ", event);
  const bucket = event.Records[0].s3.bucket.name;
  const filename = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
  const message = `File is uploaded in - ${bucket} -> ${filename}`;
  console.log(message);

  var params = {
    Bucket: process.env.SOURCE_BUCKET,
    //Key: data.document.s3Key
    Key : event.Records[0].s3.object.key
  };

  const tempFileName = `/tmp/${filename}`;
  console.log(tempFileName)
  var tempFile = fs.createWriteStream(tempFileName);

const s3 = new S3();
  var s3Stream = s3.getObject(params).createReadStream().pipe(tempFile);

  // Listen for errors returned by the service
  s3Stream.on('error', function(err) {
  // NoSuchKey: The specified key does not exist
  console.error(err);
});

s3Stream.pipe(tempFile).on('error', function(err) {
  // capture any errors that occur when writing data to the file
  console.error('File Stream:', err);
}).on('close', function() {
  console.log('Done.');
});


   console.log(filename)
  if (!canBeConvertedToPDF(filename)) {
    console.log('In false method')
    return false;
  }

  let convertedPath = await convertTo(filename, 'pdf')
  console.log('file converted')
  console.log(convertedPath)


  const outputFilename = `${parse(filename).name}.pdf`;
  const outputFileBuffer = readFileSync(`/tmp/${outputFilename}`);

  await s3
  .upload({
    Bucket: process.env.DESTINATION_BUCKET, Key: outputFilename, Body: outputFileBuffer,
    ACL: 'public-read', ContentType: 'application/pdf'
  })
  .promise();


  return `https://s3.amazonaws.com/${bucket}/${outputFilename}`;
};

Observation : Lambda timeout period is 15 min . If i try invoking lambda after 15 min, it will work and generates correct output generating PDF. Subsequent document job again will produce blank pdf’s.

@vladgolubev @KnupMan Any pointers ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vladgolubevcommented, Jun 20, 2022

We’ve released a major version of this package that works with the latest LibreOffice 7.3!

Check out the docs for a new package here.

We’re not going to support the previous version of a package that worked with a Lambda Layer and an old 6.4 version of LibreOffice.

Feel free to (re)-open a new issue in regards to the recent package version.

1reaction
bogdankharchenkocommented, Jul 1, 2021

thank so much @andrijan

Using writeFileSync vs async definitely solved my problem as well!

❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top Methods to Fix Blank PDF Problem - Wondershare Repairit
When you open a PDF document, it may be blank due to a corrupt Adobe Acrobat installation. To resolve troubles with the Acrobat...
Read more >
How to fix a fillable PDF that shows blank fields.
If the fillable fields in a PDF show as blank after getting filled in, the PDF will need to be printed to a...
Read more >
Solved: My Adobe PDF form appears blank - 8365298
Open the PDF form in Acrobat Pro or Standard (paid desktop app), clear all of the text fields, then fill out the form...
Read more >
Solved: PDF Returned from HTTP Response is Blank
I know that the PDF document is generated successfully because I can both download it from the step where it is created and...
Read more >
PDF is blank when downloading using javascript
You are using a media type "text/pdf"; this is asking for trouble, pdf is not a text format, it is binary, and treating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found