jesse0225 2022-08-12 15:36 采纳率: 0%
浏览 74

Vue用pdfJs将页面导出成pdf时报错

我想要达到的结果

img

install(Vue, options) {
    Vue.prototype.getPdf = function(htmlTitle) {
      var title = htmlTitle;
      html2Canvas(document.querySelector('#pdfDom'), {
        allowTaint: true
      }).then(function(canvas) {
        console.log(canvas.height, 'canvas.height');
        let contentWidth = canvas.width;
        let contentHeight = canvas.height;
        let pageHeight = (contentWidth / 592.28) * 841.89;
        let leftHeight = contentHeight;
        let position = 0;
        let imgWidth = 595.28;
        let imgHeight = (592.28 / contentWidth) * contentHeight;
        let pageData = canvas.toDataURL('image/jpeg', 1.0);
        let PDF = new JsPDF('', 'pt', 'a4');
        if (leftHeight < pageHeight) {
          PDF.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);
        } else {
          while (leftHeight > 0) {
            PDF.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight);

            leftHeight -= pageHeight;

            position -= 841.89;

            if (leftHeight > 0) {
              PDF.addPage();
            }
          }
        }
        PDF.save(title + '.pdf');
      });
    };
  }

  • 写回答

1条回答 默认 最新

  • 崽崽的谷雨 2022-08-12 15:58
    关注

    htmltopdf里面的错。代码发出来看看

    评论

报告相同问题?

问题事件

  • 创建了问题 8月12日

悬赏问题

  • ¥15 关于stm32hal库驱动ft6336触摸屏遇到的问题
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
  • ¥15 数字信号处理考试111
  • ¥100 关于#audobe audition#的问题,如何解决?
  • ¥15 allegro17.2生成bom表是空白的
  • ¥15 请问一下怎么打通CAN通讯
  • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
  • ¥35 navicat将excel中的数据导入mysql出错
  • ¥15 rt-thread线程切换的问题
  • ¥15 高通uboot 打印ubi init err 22