【记录】FineReport8.0中frm表单自定义打印,window.print去除页眉页脚

这是在使用帆软(FineReport)进行图表展现时碰到的问题

想要做一个页面打印,根据帮助文档,客户端有三种打印方式:

客户端打印:
Applet打印:需要安装32JDK
Flash打印:需要安装Flash,但是点击打印后出现,正在打印,无动作
PDF打印:com.fr.web.core.FormSessionIDInfor cannot be cast to com.fr.web.core.ReportSessionIDInfor

一种都用不了,只能使用js进行页面打印:

添加打印按钮:点击事件为

window.print(); 

没错,就是这一行

但是打印时不想出现页眉与页脚

这点可以使用css设置,但是FineReport嵌入引用css有些问题--无效!

    <style media="print">
    @page {
        size: auto;
        margin: 0mm;
    }
    </style>

所以我的做法是直接将css内容直接在页面加载时添加到head标签中去

即frm中body层的初始化事件

$('<style media="print"> @page { size: auto;   margin: 0mm;  } </style>').appendTo('head');

顺利

另外,如果使用IE打印的话,则在打印的点击事件中添加(因为我电脑未连打印机,也没通过IE看到预览页面,所以不知IE效果如何),但是添加以下方法稳,

 if (!!window.ActiveXObject || "ActiveXObject" in window) {
        remove_ie_header_and_footer();
    }
    window.print();
  function remove_ie_header_and_footer() {
    var hkey_root, hkey_path, hkey_key;
    hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
    try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite(hkey_path + "header", "");
        RegWsh.RegWrite(hkey_path + "footer", "");
    } catch (e) {}
}
原创文章 88 获赞 41 访问量 16万+

猜你喜欢

转载自blog.csdn.net/Damionew/article/details/88182950