• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

143
Views
How can I download generated PDF by html-pdf-node library, node and React JS and graphQL

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?

almost 3 years ago · Santiago Gelvez
1 answers
Answer question

0

Alhamdulillah! I have solved the problem simply by converting the buffer into base64 then converting the base64 into PDF.

almost 3 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error