2016-04-01 8 views
0

Zum Beispiel habe ich lokale PDF-Datei, die 6 Seiten enthält. Wenn ich window.print() Funktion verwende, wird in der Druckvorschau nur eine Seite angezeigt, was immer im Browser. Statt einer einzelnen Seite muss ich alle Seiten im Druckvorschau-Modus anzeigen.So drucken Sie lokale PDF-Datei mit Javascript

+0

Freunde keine Antworten willkommen !!! –

Antwort

0

Binden Sie alle erforderlichen Seiten oder Daten um ein Div und drucken Sie stattdessen ein Div und zum Drucken eines Div müssen Sie nur so viel Code platzieren.

<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>