Window.print 没有打印整个页面 [英] Window.print is not printing the whole page

查看:193
本文介绍了Window.print 没有打印整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的 jsp 中创建一个包含 60 列的报告表.我可以通过滚动查看所有列.现在我想打印这份报告.我用来打印的功能是

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();    
}   

现在的问题是它只打印屏幕上可见的内容,即打印的纸张只有大约 10 列在屏幕上可见.但我也想在下一页打印剩余的列,以便打印整个表格.有什么建议吗?

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?

推荐答案

remove

style="溢出:滚动;"

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

更新:我强烈建议您发送 PDF,而不是试图强制浏览器按照您的意愿打印您的页面

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

这篇关于Window.print 没有打印整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆