Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
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?

about 4 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.

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!