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

351
Views
Lienzo JsPDF a pdf acelera la velocidad de generación

Estoy usando jspdf y canvas para descargar div específicos en mi página como pdf pero toma 2 o 3 segundos y mi cliente quiere que sea rápido para descargar, ¿hay alguna forma de acelerar este proceso o disminuir el tamaño del archivo porque son 8MB pero?

el código

 $('#print').click(function (e) { e.preventDefault(); let HTML_Width = $(".report").width(); let HTML_Height = $(".report").height(); let top_left_margin = 1; let PDF_Width = HTML_Width + (top_left_margin * 2); let PDF_Height = (PDF_Width * 1.5) + (top_left_margin * 2); let canvas_image_width = HTML_Width; let canvas_image_height = HTML_Height; let totalPDFPages = Math.ceil(HTML_Height / PDF_Height) - 1; html2canvas($(".report")[0]).then(function (canvas) { let imgData = canvas.toDataURL("image/png", 1.0); let pdf = new jsPDF('p', 'pt', [PDF_Width, PDF_Height]); pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, canvas_image_width, canvas_image_height); for (let i = 1; i <= totalPDFPages; i++) { pdf.addPage(PDF_Width, PDF_Height); pdf.addImage(imgData, 'JPG', top_left_margin, -(PDF_Height * i) + (top_left_margin * 4), canvas_image_width, canvas_image_height); } pdf.save("Report.pdf"); $(".html-content").hide(); });

});

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hay 2 componentes que componen la mayor parte de la actuación. La cantidad de datos y la compresión.

La cantidad se puede reducir seleccionando un DPI más bajo: 72 para documentos de lectura de pantalla es razonable, pero podría no ser excelente si la intención es imprimir.

Para html2cavas terminamos con una escala de 3,125 para reducir esta densidad de píxeles. (Es parte del parámetro de opciones). No recuerdo los detalles, esto podría dar como resultado alrededor de 96 ppp.

Para la compresión, puede jugar con las opciones, terminamos usando la compresión 'FAST' en pdf.addImage.

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