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.

Load from Google Cloud Storage returns an empty file with no page

See original GitHub issue

Hello,

Thanks for your library. I’ve tried to make it work but I’m kinda stuck so I’m writing here.

I’m trying to load a pdf and generate a 10 pages extract thanks to a cloud function triggered at the moment the upload is complete in Google Cloud Storage.

To do so, here is my code:

  const [[content], { connection }] = await Promise.all([
    manuscriptsBucket.file(manuscriptFileName).download(),
    Mongo.connect(),
  ]);

  const [extract, original] = await Promise.all([
    PDFDocument.create(),
    PDFDocument.load(content.buffer, { throwOnInvalidObject: true }),
  ]);
 
  await extract.copyPages(original, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
  const savedExtract = await extract.save();

  logger.info(`Writing extract document to temporary file...`);
  const filename = `${manuscriptMetadata.filename.split(".")[0]}_extract.pdf`;
  const temporaryLocalFile = path.join(os.tmpdir(), filename);

  fs.appendFileSync(temporaryLocalFile, savedExtract);

  logger.info(`Successfully generated extract.`);

content here is supposed to be a Buffer so I tried to pass the underlying UInt8Array representation to your lib, but the result is the same, the pdf is empty and there is no pages inside. Obviously, the copyPages is not copying anything apart from the blank page and the extract is empty as well.

However, it does not throw an error of any kind during the process 😞 Do you have an insight of why the pdf loaded is empty and have no pages inside?

Note: I’ve successfully opened/downloaded the uploaded PDF from the Google Cloud Storage, there is no issue with the uploaded file. Below is a screenshot of the original var content supposed to contain the loaded file:

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Hopdingcommented, Oct 18, 2020

No worries! Glad it’s working.

The reason you have to add them manually is that the pages can be added to the recipient document in any order. You could interleave them, or add them backwards, for example. You could even add the same page to the recipient document multiple times. This API allows for that kind of flexibility.

0reactions
axelvaindalcommented, Oct 18, 2020

Alright, very clear. Really great job with this library, thanks a lot for your help and your availability!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting | Cloud Storage
This page describes troubleshooting methods for common errors you may encounter while using Cloud Storage. See the Google Cloud Status Dashboard for ...
Read more >
Why bucket always returns empty array of files? - Stack Overflow
I made a cloud function, which is not working, even though when everything seems to be right settle. index.js const {Storage} = require('@google...
Read more >
Upload files with Cloud Storage on Web - Firebase
Cloud Storage for Firebase allows you to quickly and easily upload files to a Cloud Storage bucket provided and managed by Firebase.
Read more >
Cloud Storage Go Reference
Package storage provides an easy way to work with Google Cloud Storage. ... a bucket. // It is always empty for BucketAttrs returned...
Read more >
Fix problems uploading files on the OneDrive website
Invalid file names and file types in OneDrive and SharePoint ... Sorry, OneDrive can't upload folders or empty files ... You're out of...
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