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

155
Views
Convertir una tabla HTML en un documento PDF

Tengo un programa React que genera tablas HTML y necesito hacer un botón que pueda convertir todo esto en un documento PDF con cada tabla en una página diferente. Intenté usar js-pdf, sin embargo, hay un error en el que la función html no se ejecuta cuando se ejecuta varias veces. Intenté hacer varios documentos con una tabla en una página y fusionarlos con pdf-lib.

 async function mergePDF(pdfs) { var doc = await PDFDocument.load(pdfs[0]); for (let index = 1; index < pdfs.length; index++) { const element = await PDFDocument.load(pdfs[index]); const copiedPages = await doc.copyPages(element, element.getPageIndices()); copiedPages.forEach((page) => doc.addPage(page)) } return doc; } async function DownloadPDF() { // Generates the PDF var margin = 10; // Gets the tables var months = document.getElementsByClassName("month"); var docs = []; for (let index = 0; index < months.length; index++) { var doc = new jsPDF("l", "px", [months[index].clientWidth + margin * 2, months[index].clientHeight + margin * 2.3]); await doc.html(months[index], { x: 0, y: 0, margin: margin }); docs.push(doc.output("arraybuffer")); } var mergedPDF = await mergePDF(docs); }

Este enfoque funciona, el único problema es que es lento, no parece generar la primera tabla y parece demasiado ineficiente. ¿Hay una mejor solución para esto?

about 4 years ago · Juan Pablo Isaza
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!