javascript - Jspdf问题内容很大时不显示到另一个页面
问题描述
I am using jspdf here is my code problem is when content is large it does not show content to next page i am trying it from a week doesn't find answer please help ?
我也尝试过 fromhtml 功能,但它订购内容到一行不支持引导程序?我也尝试过 pageSplit 拉伸内容并使其模糊?
<script>
function gen(){
let doc = new jsPDF('p','pt','a4');
doc.addHTML(document.getElementById('booking_review'),function() {
var hei=$('#booking_review').height();
if(hei > 1498){
alert("height");
doc.addPage();
doc.save('html.pdf');
}
else{
doc.save('html.pdf');
}
});
}
</script>
解决方案
我可能会迟到,但这就是我想出的……
var doc = new jsPDF("p", "mm", "a4");
var imgWidth = 210; // The width of jsPDF file. If you want the content to match the page's width
var pageHeight = 295; //
var frameHeight = canvas.height // eg. $('#booking_review').height();
var frameWidth = canvas.width // $('#booking_review').width();
var imgHeight = frameHeight * imgWidth / frameWidth
var heightLeft = imgHeight
var heightPosition = 0
doc.addImage(this.src, 'JPEG', 0, heightPosition, imgWidth, imgHeight);
heightLeft -= imgHeight
while(heightLeft >= 0){
heightPosition = heightLeft - pageHeight;
doc.addPage();
doc.addImage(this.src, 'JPEG', 0, heightPosition, imgWidth, imgHeight);
heightLeft -= imgHeight
}
doc.save('html.pdf')
这对我有用...只需尝试根据自己的喜好调整它:D
推荐阅读
- node.js - 无服务器:Lambda 仅在控制台/ Lambda 间歇性行为发生更改后才开始工作
- python - 使用 MongoEngine 在应用程序启动时定义集合名称的正确方法是什么?
- java - 使用 tomcat 时出现 java.io.FileNotFoundException
- binary-search - 二进制搜索模板 Leetcode,它的含义是什么?
- haskell - 如何从 Golang 调用 Haskell 函数?
- javascript - 将javascript数组数据传递给php并使用它来更改if else语句中的数据
- django - 使用 Django DRF 在 ArrayModelField 中进行 POST 和 PATCH 操作
- java - 允许在 Android webview 中导航
- python - str.contains only 和确切的值
- selenium-webdriver - 为什么 TestNG 可选参数带有双引号