html2PDF

阅读更多
https://github.com/eKoopmans/html2pdf

npm install html2pdf.js -save--dev


import html2pdf from 'html2pdf.js'

genPdf () {
      let dom2Print = document.querySelector('.content')
      let originWidth = dom2Print.style.width
      dom2Print.style.width = '800px'
      this.printingPDF = true
      let _this = this
      setTimeout(() => { // 足够的时间调整页面宽度
        let filename = 'xxx.pdf'
        html2pdf().from(dom2Print).save(filename).then(() => {
          dom2Print.style.width = originWidth
          _this.printingPDF = false
        })
      }, 1000)
    }
  }

// 在新的tab中打开
html2pdf().from(dom2Print).set(opt).toPdf().get('pdf').then(function (pdf) {
  window.open(pdf.output('bloburl'), '_blank')
})

你可能感兴趣的:(html2pdf)