Pdfmake in node.js to download pdf to flutter application
Pdfmake has an option to 'pipe' the generated doc directly to the client. So, if you pass the response object to the code that generates the pdf, it will be something like:
var printer = new PdfPrinter(fonts);
//Assuming pdf is your generated PDF:
doc = printer.createPdfKitDocument(pdf);
res.setHeader('Content-type', 'application/pdf');
res.setHeader('Content-disposition', 'inline; filename="nice.pdf"');
doc.pipe(res);
doc.end();
TheNoobDeveloper0299
Updated on December 24, 2022Comments
-
TheNoobDeveloper0299 over 1 year
So what I exactly want to do is, Generate a pdf for an order in my order management system.
I am using node.js as the backend and flutter as the front end.
What I had in my mind is: Generate the pdf and store it on the server, return the link to the pdf to the flutter app and then download the pdf, but I don't want to store the pdf on the server, so when my flutter app calls the generatePdf endpoint using GET method, how can I send the pdf directly? Do I need to use res.download ? I am new to node.js and cannot understand the flow for downloading the file. Also, how do I need to change the request in my flutter app for the same?
Note: I am using PDFMake to generate the pdf.