2016-04-01 23 views
0

Örneğin, 6 sayfa içeren yerel pdf dosyasına sahibim. window.print() işlevini kullanırsam, Yazdırma önizlemesinde tarayıcıda ne olduğunu yalnızca bir sayfada göstereceğim. Tek sayfa yerine tüm sayfaları baskı önizleme modunda göstermem gerekiyor.Yerel pdf dosyasını javascript kullanarak yazdırma

+0

Arkadaşlar herhangi bir cevap hoşgeldiniz! –

cevap

0

Tüm gerekli sayfaları veya bir div çevresindeki verileri bir araya getirin ve bunun yerine div yazdırın ve bir div yazdırmak için bu kodu çoğaltmanız yeterlidir.

<html> 
<head> 
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript"> 

    function PrintElem(elem) 
    { 
     Popup($(elem).html()); 
    } 

    function Popup(data) 
    { 
     var mywindow = window.open('', 'my div', 'height=400,width=600'); 
     mywindow.document.write('<html><head><title>my div</title>'); 
     /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />'); 
     mywindow.document.write('</head><body >'); 
     mywindow.document.write(data); 
     mywindow.document.write('</body></html>'); 

     mywindow.document.close(); // necessary for IE >= 10 
     mywindow.focus(); // necessary for IE >= 10 

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

     return true; 
    } 

</script> 
</head> 
<body> 

<div id="mydiv"> 
    This will be printed. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a quam at nibh adipiscing interdum. Nulla vitae accumsan ante. 
</div> 

<div> 
    This will not be printed. 
</div> 

<div id="anotherdiv"> 
    Nor will this. 
</div> 

<input type="button" value="Print Div" onclick="PrintElem('#mydiv')" /> 

</body> 
</html> 
İlgili konular