Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

504
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda