Shewbii
Shewbii

Reputation: 55

NodeJS - Generate PDF on the fly with pdfmake

I would like, in my NodeJS app, to generate a PDF in server-side with pdfmake but i don't know how to do. I would like to don't save it on my server.

I have this

const printer = new PdfPrinter( fonts );
const pdfKitDoc = printer.createPdfKitDocument( dd );
const stream = pdfKitDoc.pipe( ... );
pdfKitDoc.end();
return stream;

and I don't know what I have to type instead of '...'. If it's possible, I would like to stream it as blob to use it in my apps.

Can anyone help me ?

Thanks

Upvotes: 1

Views: 2051

Answers (1)

Shewbii
Shewbii

Reputation: 55

I solved my problem thanks to @Thee Sritabtim.

  1. Install stream-to-array
  2. Then

return toArray( doc ).then( parts => {
   return Buffer.concat( parts );
} );

Upvotes: 1

Related Questions