admin管理员组文章数量:1420918
how to add margin-bottom and top at multiple pages pdf?
I added plugins jspdf and html2canvas.
var pdf = new jsPDF( 'p', 'mm', [400, 455]);
var specialElementHandlers = {
'#exportthis': function (element, renderer) {
return true;
}
};
margins = {
bottom:10,
top:10,
left:10,
right:10
};
pdf.addHTML(document.getElementById('exportthis'), 5, 10, {pagesplit: true },
function(dispose){
var pageCount = pdf.internal.getNumberOfPages();
for(i = 0; i < pageCount; i++) {
pdf.setPage(i);
pdf.text(195,450, pdf.internal.getCurrentPageInfo().pageNumber + "/" + pageCount +"\n");
}
pdf.save("Report.pdf");
},margins);
output
how to add margin-bottom and top at multiple pages pdf?
I added plugins jspdf and html2canvas.
var pdf = new jsPDF( 'p', 'mm', [400, 455]);
var specialElementHandlers = {
'#exportthis': function (element, renderer) {
return true;
}
};
margins = {
bottom:10,
top:10,
left:10,
right:10
};
pdf.addHTML(document.getElementById('exportthis'), 5, 10, {pagesplit: true },
function(dispose){
var pageCount = pdf.internal.getNumberOfPages();
for(i = 0; i < pageCount; i++) {
pdf.setPage(i);
pdf.text(195,450, pdf.internal.getCurrentPageInfo().pageNumber + "/" + pageCount +"\n");
}
pdf.save("Report.pdf");
},margins);
output
Share Improve this question edited Aug 3, 2018 at 13:22 Aliaksandr Pitkevich 8348 silver badges25 bronze badges asked Aug 3, 2018 at 13:19 Rushi daveRushi dave 1642 gold badges6 silver badges20 bronze badges 2- Have a look at this: stackoverflow./questions/46012181/… – Sookie Singh Commented Aug 3, 2018 at 13:22
- I try this but same error and tx for response@Er_sherlockian – Rushi dave Commented Aug 3, 2018 at 13:24
3 Answers
Reset to default 2Do it like this:
pdf.addHTML(document.getElementById('exportthis'), 5, 10, {
pagesplit: true,
margin: margins
},
function(dispose) {
var pageCount = pdf.internal.getNumberOfPages();
for (i = 0; i < pageCount; i++) {
pdf.setPage(i);
pdf.text(195, 450, pdf.internal.getCurrentPageInfo().pageNumber + "/" + pageCount + "\n");
}
pdf.save("Report.pdf");
});
JSPDF allows margin and useFor Feature. You can set the margin properties like below:
const pdf = new jspdf('p', 'pt', 'a4'); // For A4 Sheet layout
pdf.addHTML(document.getElementById('print-section'), 25, 50, {
retina: true,
pagesplit: true,
margin: {
top: 50,
right: 25,
bottom: 50,
left: 25,
useFor: 'page' // This property is mandatory to keep the margin to supsequent pages
}
}, function() {
pdf.save('test.pdf');
});
See the output below:
I solved this issue using changes of the addhtml.js file
https://github./MrRio/jsPDF/pull/1450/files and its work for me
本文标签: javascripthow to set top and bottom margin in addHTMLStack Overflow
版权声明:本文标题:javascript - how to set top and bottom margin in addHTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745343484a2654372.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论