Load from Google Cloud Storage returns an empty file with no page
See original GitHub issueHello,
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:

Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
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.
Alright, very clear. Really great job with this library, thanks a lot for your help and your availability!