Doubt on pdf download

async function generateAuditPDF(filteredAudits) {
const htmlContent = generateHTML(filteredAudits);
const puppeteer = require(“puppeteer”);
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(htmlContent);
const pdfBuffer = await page.pdf({
format: “A4”,
printBackground: true
});
await browser.close();
return pdfBuffer;
}
const pdfBuffer = await generateAuditPDF(bh.input.findResult);
bh.local.pdf=pdfBuffer
return bh;

how to do pdf download properly , now iam setting pdfBuffer into bh.local.pdf ,how i process the downloading

1 Like

Hello @navaneethck_10 , If you have the buffer, you can pass it to the frontend and convert it into a Blob.

example
// Suppose pdfBuffer is your buffer (ArrayBuffer or Uint8Array)
const downloadPDF = (pdfBuffer) => {
// Convert buffer to Blob
const blob = new Blob([pdfBuffer], { type: “application/pdf” });

// Create a download link
const url = window.URL.createObjectURL(blob);
const a = document.createElement(“a”);
a.href = url;
a.download = “document.pdf”; // file name
document.body.appendChild(a);
a.click();

// Cleanup
a.remove();
window.URL.revokeObjectURL(url);
};

1 Like

i wanna know how to send the buffer properly in http out? now when i send buffer from backend then ends with errors in postman

1 Like

Hi @Sam
Need solution for this ,

How to send pdf buffer in http out node.

Now not receiving any response.

curl -X GET http://localhost:8081/api/audits/report/pdf\?startTime\=2025-09-03T19:36:08.022Z\&endTime\=2025-09-10T12:05:34.638Z\&operation\=CREATE_BOOK \
  -H "Origin: http://localhost:4200" \
  -H "Access-Control-Allow-Origin: http://localhost:4200" \
  -o document.pdf \
-i
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:44 --:--:--     0

the response not ending.

1 Like