• 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

141
Views
¿Cómo puedo descargar el PDF generado por la biblioteca html-pdf-node, node y React JS y graphQL?

Recibo una respuesta del backend ahora, ¿cómo puedo descargar el PDF generado desde el frontend haciendo clic en el botón Exportar? Mi controlador de clic en el botón Exportar de la siguiente manera;

 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"); }); };

y mi código de fondo es;

 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; };

Recibo la siguiente respuesta en mi consola de la siguiente manera; consola.log(respuesta.datos)

ahora mi pregunta es ¿cómo puedo descargar el PDF generado usando la función saveChangeReport ?

almost 3 years ago · Santiago Gelvez
1 answers
Answer question

0

¡Alhamdulillah! Resolví el problema simplemente convirtiendo el búfer en base64 y luego convirtiendo el base64 en 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