pdf打印去掉页眉页脚(兼容ie)

问题描述:

项目中使用PDF打印,Google浏览器和ie都有默认的页眉页脚,页面四个角有时间,页码,网址,甚至还有undefined。在这里插入图片描述


解决方案:

1.使用css样式,将页眉页脚去除。
2.ie兼容处理,(js函数)

一.Chrome处理

<style scoped>
  @page {
  size:auto !important;
  height: 100% !important;
  margin: 3mm 0 0 10mm  !important;
}
</style>

二.ie处理

methods: {
    print_page() {
      if (!!window.ActiveXObject || 'ActiveXObject' in window) { // 是否ie
        this.remove()
      }
      // window.print()
    },
    remove() {
      var hkey_path
      hkey_path = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\'
      try {
        var RegWsh = new window.ActiveXObject('WScript.Shell')
        RegWsh.RegWrite(hkey_path + 'header', '')
        RegWsh.RegWrite(hkey_path + 'footer', '')
      } catch (e) {
      }
    },
   }
<el-button v-print="#toPrint" type="primary" @click="print_page">打印机打印</el-button>
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值