jspdf - jsPDF- html() 新函数没有为 pdf 页面设置边距的功能
问题描述
我在 vue cli 应用程序中使用 jsPDF,但我找不到任何解决方案来设置 pdf 页面的边距。所有的文本和图像都在页面上溢出。我想设置所有四个边距。jsPDF 文档中给出的设置边距的语法也不起作用。
这是我生成和下载 pdf 的功能:
downloadpdf() {
var pdf = new jsPDF("p", "pt", "a4");
pdf.setFontSize("10");
pdf.setLineWidth("100");
pdf.setTextColor("darkblue");
// Printing text
var vuejsinformation = `JQuery is a lightweight, "write less, do more", JavaScript library.`;
pdf.text(vuejsinformation, 10, 10);
//pdf.save("Sample.pdf");
// Printing a complete div container who has class pdfrapper
pdf.html(window.jQuery(".pdfwrapper").get(0), {
callback: function (pdf) {
pdf.save("Sample.pdf");
},
x: 10,
y: 10,
});
},
如何设置所有四个边距?
解决方案
您可以在 jspdf.html() 方法中添加一个选项 var,如下所示:
jspdf.html(src, {
margin: number,
html2canvas: {width: number, height: number, ...}
...
})
但是,似乎存在使用此方法时忽略边距的问题,请参阅https://github.com/MrRio/jsPDF/issues/2924。它可能很快就会修复:)。
这是 jspdf.html() 方法的文档http://raw.githack.com/MrRio/jsPDF/master/docs/module-html.html
推荐阅读
- java - 连接到 Google Cloud SQL com.google.cloud.sql.mysql.SocketFactory 转换时出错
- python - 用 sympy 解决绝对平等
- ios - 后台应用程序刷新说访问计步器数据时未调用完成
- apache-flink - 使用 PromQL 的 Flink Watermark 延迟
- viewer - 从forge api获取房间信息
- c - fwrite 只写入 4096 而不是 100,000 字节
- r - 当缺少序列值时将向量排序为重复序列R
- java - in 不能应用于 android studio
- android - 我无法使用解析的整数进行 api 调用
- talend - 从 Talend 中的 JSON 文件中提取值