Images not displaying when Print Preview (Or Print) in IE/Chrome/Firefox
Asked Answered
S

4

9

I'm Web Developer and almost never work with design but have been given this bug which I'm struggling to rectify.

Some images appear correctly when I print/display the print preview page, however others don't. The key difference that I can see is that the images that don't appear are span tags with the image applied in css whilst the working images use the img tag.

Here are examples of the html:

Span with "icon" birth does not display:

<li class="media">
    <div class="img">
        <div class="h2 mtm">1889</div>
        <span class="timeline-icon icon-birth"></span>
    </div>
    <div class="bd">
        <h3 class="profile-subtitle mts">Born in ?</h3>
        <p class="deemphasis mbn">
        <a href="/search/results/bmdindexedbirths/bibby/elizabeth%20?yearofbirth=1889">Search     for Birth Record</a>
        </p>
    </div>
</li>

Image.gif does display:

<li class="media">
    <div class="img">
        <div class="h6">
            <strong>Spouse</strong></div>
            <img src="image.gif" alt="" class="person-thumb dropshadow" />
        </div>
    <div class="bd">
        <p class="mbn">Husband</p>
        <h3 class="profile-subtitle">
            <a href="path">Thomas&nbsp;<strong>Name</strong></a>
        </h3>
        <p class="mbn">?&#45;?</p>
    </div>
</li>

In some browsers it looks ok in the preview but does not print, in others it doesn't and still does not print.

Thankyou in advance!

Sound answered 20/9, 2012 at 17:15 Comment(1)
The images did not print as they were background images and the browsers were set up to not print these. This can be manually changed in some browsers. Solution was to use html img tags instead of the span.Sound
R
9

I had the same problem over two months ago. I had a button that redirected users to a printer-friendly page and then I triggered print dialog using Javascript.

The problem was that browsers did not wait till images specified in CSS background were downloaded.

I put timeout before triggering the print dialog to give browser time to download images. This approach is not reliable since nobody has constant download speed and it would open the print dialog before the images are downloaded to users with very slow Internet connection.

In the end, I used HTML img tags to embed images on my page and jQuery to trigger the print dialog when the last image is downloaded.

Rheingold answered 21/9, 2012 at 14:38 Comment(1)
It turned out that images didn't show in my case as the browser default was to not print background images. This can be set manually in some browsers but not all. The solution was to use HTML img tags.Sound
M
7

You need to put delay before print. There is a native bug in chrome. Code would as under :-

function PrintDiv(data) {
    var mywindow = window.open();
    var is_chrome = Boolean(mywindow.chrome);
    mywindow.document.write(data);

   if (is_chrome) {
     setTimeout(function() { // wait until all resources loaded 
        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10
        mywindow.print(); // change window to winPrint
        mywindow.close(); // change window to winPrint
     }, 250);
   } else {
        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10

        mywindow.print();
        mywindow.close();
   }

    return true;
}
Mccauley answered 30/10, 2015 at 5:43 Comment(0)
M
1

Just add the below styles to make it work img{max-width:100%;height:auto;}

Its the width of the image being set to 0 in the print which is causing the issue.

Marthmartha answered 17/5, 2016 at 8:22 Comment(0)
P
0

make a print stylesheet, set your span to display:block

Pugliese answered 21/9, 2012 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.