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

IntoTheBlue picture IntoTheBlue · Sep 20, 2012 · Viewed 27.3k times · Source

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!

Answer

david89 picture david89 · Sep 21, 2012

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.