Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

505
Vistas
how to print a data inside a div tag using window.print() as a image

I have data like this inside a div tag which i am fetching data from MySQL using PHP and populating data using a division tag like this.

enter image description here

Issue is that i want to print this data as the image show's but, i am not getting the desired print but i am getting print like this,enter image description here

so i am trying print the div tag as image to get the print like this

enter image description here

**Code that i am using to print**
**print.php**
<div>
<button class="btn btn--radius-2 btn--blue" onclick="printDiv('printableTable')">Print</button>
                <div>
                    <div>
                        <div class="row" id="printableTable">
                            <?php

                            if (mysqli_num_rows($result) > 0) {
                                while ($row = mysqli_fetch_assoc($result)) {
                            ?>
                            <div class="col-md-4" style="background-color:white;height: 180px;">
                                <p>--------------------------------------------------------------</p>
                                <p><u><?php echo $row['ID'] ?></u></p>
                                <p>
                                    <b><?php echo $row['Fullname'] ?></b>
                                </p>
                                <?php echo $row['Address'] ?>
                                <p><?php echo $row['EmailId'] ?></p>
                                
                            </div>
                            <?php
                                }
                            }
                            ?>

                        </div>
**print.js**

function printDiv(divName) {
    var printContents = document.getElementById(divName).innerHTML;
    var originalContents = document.body.innerHTML;

    document.body.innerHTML = printContents;

    window.print();

    document.body.innerHTML = originalContents;
}

Any suggestions are welcome, i just need to print this full data in a single a4 sheet.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The function to print is not the problem, it is the CSS you have specified for printing. That is you haven't got a CSS layout, so the layout is going with the screen CSS.

Add this to your

<link rel="stylesheet" media="print" href="print.css" />

Then, inside print.css, change the definition of col-md-4 so that it flows as you wish.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda