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

510
Views
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 answers
Answer question

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 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!