From the below code I am able to print the pdf file using postman request, but while downloading from the web url not getting any response from back-end.
const fs = require('fs');
const PDFDocument = require("pdfkit-table");
const addTextbox = require("textbox-for-pdfkit");
export async function genearateInvoicePDF(data, res) {
try {
const doc = new PDFDocument({ margin: 10 });
doc.pipe(fs.createWriteStream('invoice.pdf'));
------------------
doc.end();
console.log("done")
let pdfPath = path.join(globalThis.__basedir, '../') + "invoice.pdf";
let file = fs.readFileSync(pdfPath);
let stat = fs.statSync(pdfPath);
return res.status(200).header("Content-Type", "application/pdf").send(file);
} catch (error) {
console.log({ error })
};
};
And I'm using this method to dowload pdf as follows.
export async function genearateInvoicePDF(req, res) {
try {
let data = "some data-----"
await genearateInvoicePDF(data, res);
} catch (error) {
console.log("error", error);
};
};
Whenever I try this using postman request pdf prints in the output, but while I'm sending request from the browser doesn't get any response. Please help to find a solution.
I am getting request- headers as follows:
:authority: ---- :method: GET
:path: some- path
:scheme: https
accept: application/json, text/plain, / accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9,hi;q=0.8