how to convert pdfkit object into buffer using nodejs
Asked Answered
C

1

18

I am generating pdf document using pdfkit(nodejs module).i need to convert the pdfkit object to buffer and send response as attachment file without save a file in server.

i was using output function to achieve this:

pdfdocument.output(function(buffer){
    return buffer;
});

pdfkit deprecated the output function.

so right now i dont know how to do any idea...

Cobham answered 15/5, 2014 at 19:16 Comment(1)
how can i make my pdf document not to be saved in server ?Ceyx
O
38

Working example for pdfkit v0.8.0:

let pdf = new pdfkit();

let buffers = [];
pdf.on('data', buffers.push.bind(buffers));
pdf.on('end', () => {

    let pdfData = Buffer.concat(buffers);

    // ... now send pdfData as attachment ...

});

pdf.text('Hello', 100, 100);
pdf.end();

Hope it helps :)

Omer answered 31/1, 2017 at 0:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.