I am getting response from the backend now how can I download the generated PDF from the frontend by clicking on the Export button. My Export button click handler as follows;
const handleExportProjectData = () => {
const changeStatusProjectData = JSON.stringify(project);
dataProvider
.postRequest("ExportAllProjectChangeStatus", {
queryType: "retrieve",
data: { changeStatusProjectData },
})
.then((response) => {
console.log(response.data, "data posted");
saveChangeReport(response.data);
})
.catch((error) => {
notify("No change status data found to export");
});
};
and my backend code is;
const downloadChangeStatusPDF = async (root, { changeStatusProjectData },{ user }) => {
const html_to_pdf = require("html-pdf-node");
let options = { format: "A4" };
let today = new Date();
let dd = String(today.getDate()).padStart(2, "0");
let mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
let yyyy = today.getFullYear();
today = dd + "/" + mm + "/" + yyyy;
let file = { content: "<h1>Welcome to html-pdf-node</h1>" };
let generatedPDF = await html_to_pdf.generatePdf(file, options)
.then((pdfBuffer) => {
return JSON.stringify(pdfBuffer);
});
return generatedPDF;
};
I am getting the following response in my console as follows; console.log(response.data)
now my question is how can I download the generated PDF using saveChangeReport
function?
Alhamdulillah! I have solved the problem simply by converting the buffer into base64 then converting the base64 into PDF.