jspdf - 如何控制 html2canvas 中的字体大小
问题描述
我正在使用html2pdf从 html 代码创建 pdf。它使用html2canvas和jsPDF。结果非常好,但与原版略有不同: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()]
},
解决方案
解决方案是为元素添加内联样式。就我而言,在 vuejs 中工作,我最终得到了以下代码:
<div class="presentazione" v-html="presentation" :style="presentationFont"></div>
推荐阅读
- flutter - Flutter Chopper:允许使用自签名证书吗?
- r - GGPlot2 Preset - 创建具有某些 ggplot2 美学选项的函数
- assembly - QEMU 中的小 x86-16 哔声
- qml - 在 qml 中用什么代替 TreeView?
- r - 下载报告时如何在 Shiny 应用程序中添加进度条?
- python-3.x - 比较 unicode 字符与组合变音符号
- r - R4.1.0,Windows 10,文件错误(文件,“rt”):无法打开文件 '001.csv':没有这样的文件或目录
- kubernetes - SMB 共享挂载在 Kubernetes 上,但内容不可见(文件或目录)
- python - 通过python从IB获取股票实时报价列表
- kibana - 异常检测 - 如何用作监控工具