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

235
Views
Informe generado como vista HTML, ¿puede imprimirse tal cual?

En mi aplicación quería generar el informe final de una manera más elegante y actualmente solía mostrar el informe en vista HTML/CSS.

Luego quise intentarlo imprimiendo, pero cuando lo hace, viene con la vista básica (como sin tablas, datos mal ordenados, etc.). Entonces, quiero saber si es posible enviar esta vista a la impresión como se muestra en la vista.

Encontré un javascript para la acción de impresión y este es el que usé para imprimir.

 <script type="text/javascript"> function PrintElem(elem) { Popup($(elem).html()); } function Popup(data) { var mywindow = window.open('', 'divprint', 'height=400,width=600'); mywindow.document.write('<html><head><title></title>'); /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />'); mywindow.document.write('</head><body >'); mywindow.document.write(data); mywindow.document.write('</body></html>'); mywindow.document.close(); // necessary for IE >= 10 mywindow.focus(); // necessary for IE >= 10 mywindow.print(); mywindow.close(); return true; } </script>

¿O hay alguna forma de convertir esto a pdf cuando el usuario hace clic en la impresión y luego abre ese pdf para imprimir? También quiero configurar esta vista en tamaño A4 al generarla.

Así es como se muestra mi vista ahora. Gracias

ingrese la descripción de la imagen aquí

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

0

Agregue esta biblioteca a su proyecto, enlace de descarga: https://ekoopmans.github.io/html2pdf.js/

Código HTML:

 <div id="dPDF"> Your all html here which you want to print </div> <div class="generate-pdf" onclick="downloadPDF()"> Generate PDF (Button for generating pdf) </div>

función para generar PDF:

 function downloadPDF() { const element = document.getElementById("dPDF"); var opt = { margin: 0.5, filename: 'your_filename.pdf', image: { type: 'jpeg', quality: 1 }, html2canvas: { scale: 4, logging: true }, jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' } }; html2pdf().set(opt).from(element).save(); }

Nota: Al generar y descargar el pdf, puede imprimir la vista exacta que desea.

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!