JSPDF SetPage不使用SET HTML
我创建了包含每个PDF页面的HTML的DIV元素。我尝试使用JSPDF生成PDF。问题在于,它将所有HTML页面都放在PDF文件的第一页上。
我已经尝试过此代码,
const list = [];
const pages = document.getElementsByName( this.pageName );
const pdf = new jsPDF("landscape", "px", [this.pageWidth, this.pageHeight]);
pages.forEach((el, i) => {
if (i > 0) {
pdf.addPage();
}
pdf.setPage(i + 1);
list.push(pdf.html(el));
});
Promise.all(list).then((res) => {
pdf.save("test.pdf");
}).catch(error => {
console.log('error ', error);
});
我尝试过此代码
const list = [];
const pages = document.getElementsByName( this.pageName );
const pdf = new jsPDF("landscape", "px", [this.pageWidth, this.pageHeight]);
pages.forEach((el, i) => {
if (i > 0) {
pdf.addPage();
}
list.push(pdf.html(el, {x: 0, y: (i * this.pageHeight)}));
});
Promise.all(list).then((res) => {
pdf.save("test.pdf");
}).catch(error => {
console.log('error ', error);
});
addPage
正常工作,它生成了空白页,但是它仍然将所有HTML页面放在PDF文件的第一页上。因此,某种程度上pdf.setpage(i + 1);
and {x:0,y:(i * this.pageHeight)}
解决方案不起作用。
I have created div elements which contains html of each PDF page. I try to generate PDF using jsPDF. The issue is that it puts all html pages on PDF file's first page.
I have tried this code
const list = [];
const pages = document.getElementsByName( this.pageName );
const pdf = new jsPDF("landscape", "px", [this.pageWidth, this.pageHeight]);
pages.forEach((el, i) => {
if (i > 0) {
pdf.addPage();
}
pdf.setPage(i + 1);
list.push(pdf.html(el));
});
Promise.all(list).then((res) => {
pdf.save("test.pdf");
}).catch(error => {
console.log('error ', error);
});
I have tried this code
const list = [];
const pages = document.getElementsByName( this.pageName );
const pdf = new jsPDF("landscape", "px", [this.pageWidth, this.pageHeight]);
pages.forEach((el, i) => {
if (i > 0) {
pdf.addPage();
}
list.push(pdf.html(el, {x: 0, y: (i * this.pageHeight)}));
});
Promise.all(list).then((res) => {
pdf.save("test.pdf");
}).catch(error => {
console.log('error ', error);
});
addPage
works fine, it generates blank pages, but it still puts all html pages on PDF file's first page. So somehow pdf.setPage(i + 1);
and {x: 0, y: (i * this.pageHeight)}
solutions are not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我能够强迫JSPDF将HTML内容放在相应的页面上。这是解决方案。
解决方案看起来有些复杂,因此,如果有人知道更好的解决方案,欢迎您。
Finally I was able to force jsPDF to put HTML contents on corresponding pages. Here is the solution.
Solution looks a bit complicated, so if someone knows better solution, you are welcome.