2017-07-20 31 views
-1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Coupon Page</title> 

    <script type="text/javascript"> 
     function printCoupon() { 
      var timeout = 1000; 

      self.focus(); 
      window.print(); 
      setTimeout("self.close()", timeout);; 
      self.focus(); 
     } 
    </script> 

</head> 

<body onload="printCoupon();"> 

    <p><img src="https://nebula.phx3.secureserver.net/2247f0de910e14f95483f60fdae499a0? 
    AccessKeyId=8BBF3308EC59517C0B34&disposition=0&alloworigin=1" originalattribute="src" originalpath="coupon.jpg" width="585" height="250"> 
    </p> 

</body> 

</html> 

我搜索HTML編碼打印圖像(w585 W250),圖像的實際大小,或相關的按鈕被點擊,只有當網頁圖像。我發現編碼完美,但打印出來的圖像真的沒有焦點。編碼你看這個地址通過陳述重點,這樣,我已經爲此工作了一個月附近沒有成功,請幫助需要HTML代碼僅打印網頁的形象,在重點

回答

0

您可以嘗試在CSS媒體查詢打印圖像。

0

檢查naturalWidthnaturalHeight與圖像width比較和height因此,如果他們再print頁面匹配。

function printCoupon() { 
 
    var timeout = 1000; 
 

 
    var naturalWidth = $('#img')[0].naturalWidth; 
 
    var naturalHeight = $('#img')[0].naturalHeight; 
 

 
    var width = $('#img').width() 
 
    var height = $('#img').height(); 
 

 
    if (naturalWidth == width && naturalHeight == height) { 
 

 
    self.focus(); 
 
    window.print(); 
 
    setTimeout("self.close()", timeout);; 
 
    self.focus(); 
 
    } 
 

 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
 

 
<body onload="printCoupon();"> 
 

 
    <p><img id="img" src="https://nebula.phx3.secureserver.net/2247f0de910e14f95483f60fdae499a0? 
 
AccessKeyId=8BBF3308EC59517C0B34&disposition=0&alloworigin=1" originalattribute="src" originalpath="coupon.jpg" width="585" height="250"> 
 
    </p>