Window.print is not printing the whole page

允我心安 提交于 2019-12-24 08:27:05

问题


I am creating a report table in my jsp which contains 60 columns. I can see all the columns by scrolling. Now I want to print this report. The function I am using to print is

function printReport(rpt)
{       
    var report = document.getElementById(rpt);
    var newWindow = "toolbar=no, addressbar=no, directories=no,location=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=5000 , height=500, left=50, top=50";
    var printWindow = window.open('',rpt, newWindow);
    printWindow.document.write('<html><body>');
    printWindow.document.write('<div id="rpt" name="rpt" style="overflow:scroll;" >');
    printWindow.document.write(report.innerHTML);       
    printWindow.document.write('</div>');
    printWindow.document.write('</body></html>');
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();    
}   

Now the problem is it only prints the content which is visible on screen i.e the printed paper only has around 10 columns which are visible on screen. But I want to print the remaining columns also in the next page so that whole table is printed. Any Suggestions?


回答1:


remove

style="overflow:scroll;"

or even just this (and note that I first removed the spaces in the parms and then removed most of them since they are irrelevant)

function printReport(rpt)
{       
    var report = document.getElementById(rpt);
    var parms = "scrollbars,resizable,width=500,height=500,left=50,top=50";
    var printWindow = window.open('',rpt, parms);
    printWindow.document.write('<html><body onload="window.focus();window.print()">');
    printWindow.document.write(report.innerHTML);       
    printWindow.document.write('</body></html>');
    printWindow.document.close();
    printWindow.close(); // not sure this is ok either.   
}  

UPDATE: I strongly suggest you send a PDF instead of trying to force the browser to print your page like you want



来源:https://stackoverflow.com/questions/9802630/window-print-is-not-printing-the-whole-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!