download

一、使用步骤

1.引入库

下载插件printjs并再页面引入

import printJS from 'print-js'

代码如下(示例):

 handlePrint(params) {
      // this.$Print('#pdfFile')
      // this.pdfShow = true
      console.log(this.selectionList, 'selectionList')
      if (this.selectionList.length == 0) {
        this.$message.warning('请选择一个合同')
      } else if (this.selectionList.length > 1) {
        this.$message.warning('只能选择一个合同')
        return
      }
      //
      if (this.selectionList[0].templateId == -1) {
        this.$message.warning('当前合同未配置合同模板,无法打印!')
      } else {
        downloadContract({
          id: this.selectionList[0].id,
          // templateId: 1,
        }).then(res => {
          console.log(res, 'res999')
          let pdfUrl = ''
          if(window.location.protocol == 'http:'){
            // http
            pdfUrl = res.data.data
          }else{
            // https
            pdfUrl = res.data.data.replace("http:","https:")
          }
          // 渲染到页面
          printJS({
            printable: pdfUrl, // 'printFrom', // 标签元素id
            // 'http://whsle-hopdata-dev.oss-cn-hangzhou.aliyuncs.com/upload/20231113/2c5f011b81adce116f1acabd0da2efb5.pdf', // 'printFrom', // 标签元素id
            type: 'pdf',
            // header: 'ceshi', // '表单',
            targetStyles: ['*'],
            style: '@page {margin:0 10mm};', // 可选-打印时去掉眉页眉尾
            ignoreElements: ['no-print'], // ['no-print']
            properties: null,
          })
        })
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值