Click here to Skip to main content
15,938,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey all, I am attempting to merge n files of pdfs (up to 1000 at times) into a single pdf.The pdfs are stored on GoogleStorage and I have the option of getting the files in 1 of 3 ways.

Either a Readable Stream
TypeScript
return this.storage.bucket(bucket).file(path).createReadStream();

Or a File object (a GCP class)
TypeScript
this.storage.bucket(bucket).file(path);

Or to simply download the files that actually returns a Promise<buffer>
TypeScript
readFile({ bucket, path }: BucketFileConfig): Promise<Buffer> {
  const file = this.storage.bucket(bucket).file(path);
  return new Promise((resolve, reject) => {
    file.download((err, buffer) => {
      if (err) {
        this.logger.error(err, path);
        reject(err);
      } else {
        resolve(buffer);
      }
    });
  });
}


The thing is the third options does not seem feasible with 1000+ pdfs, I inted on using a package called pdf-lib to merge all the pdfs afterwards, and the issue is it only accepts buffer or read local files. What would be an ideal way to deal with an issue like this, do I simply go for the third options or is there something I'm missing here ? Any help is much appreciated!

What I have tried:

All attempt are in problem description
Posted
Updated 9-Sep-22 1:32am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900