8

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!

IntoTheBlue
  • 189
  • 1
  • 3
  • 9
  • 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. – IntoTheBlue Sep 28 '12 at 09:10

4 Answers4

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.

david89
  • 799
  • 4
  • 8
  • 2
    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. – IntoTheBlue Sep 28 '12 at 09:06
5

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;
}
Anand Deep Singh
  • 2,247
  • 2
  • 18
  • 25
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.

0

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

albert
  • 7,915
  • 3
  • 42
  • 62