首页 > 解决方案 > 如何控制 html2canvas 中的字体大小

问题描述

我正在使用html2pdf从 html 代码创建 pdf。它使用html2canvasjsPDF。结果非常好,但与原版略有不同:font-size 和 line-height 有点不同,因此页面末尾不正确。如果 div (具有在 A4 页面上正确呈现的固定方面),我真的需要一份副本。

有没有办法影响最终渲染中的字体?我现在制作pdf的方式是:

   savePdf () {
      this.pdfDialog = true
      let opt = {
        // if set firefox will not be able to print as pdf!...
        // margin: 0,
        filename: 'cv.pdf',
        enableLinks: true,
        image: { type: 'jpeg', quality: 0.98 },
        html2canvas: {
          scale: 8,
          useCORS: true,
          width: 310,
          letterRendering: true,
        },
        jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
      }
      html2pdf().set(opt).from(document.getElementById('printable-cv')).save()]
},

标签: jspdfhtml2canvashtml2pdf

解决方案


解决方案是为元素添加内联样式。就我而言,在 vuejs 中工作,我最终得到了以下代码:

<div class="presentazione" v-html="presentation" :style="presentationFont"></div>

推荐阅读