jspdf 打印多页时两边取消留白,带有HTML渲染器的jsPDF多页PDF

作者在使用jsPDF时遇到将多个div内容整合到单个PDF的问题,内容可能跨越2-3页。寻求解决方案,提到MrRio的github issue中提及需频繁检查页面大小并重新开始高度定位。讨论了如何通过API控制页面添加和内容布局来实现跨页内容正确显示。
摘要由CSDN通过智能技术生成

I am using jsPDF in my site to generate PDFs. But now I have multiple DIVs to print in a single PDF. which may take 2 to 3 pages.

For example:

content

content

content

my JS code

This works but not as I expected, It add a part of the content(which cannot be included in more than one page).

It removes html tags like br, h1 etc.

function formtoPDF() {

jsPDF.API.mymethod = function() {

// 'this' will be ref to internal API object. see jsPDF source

// , so you can refer to built-in methods like so:

// this.line(....)

// this.text(....)

};

var doc = new jsPDF();

doc.mymethod();

var pdfPart1 = jQuery('#genPDFpart1');

var pdfPart2 = jQuery(".ltinerary");

var pdfPart3 = jQuery("#domElementHTML");

var specialElementHandlers = {

'#loadVar': function(element, renderer) {

return true;

}

};

doc.fromHTML(pdfPart1.html() + pdfPart3.html() + pdfPart3.html(), 15, 15, {

'width': 170,

'elementHandlers': specialElementHandlers

});

doc.output('save', 'Download.pdf');

}

Can I have a solution for this. Thanks in advance pals .

解决方案

I have the same working issue. Searching in MrRio github I found this: https://github.com/MrRio/jsPDF/issues/101

Basically, you have to check the actual page size always before adding new content

doc = new jsPdf();

...

pageHeight= doc.internal.pageSize.height;

// Before adding new content

y = 500 // Height position of new content

if (y >= pageHeight)

{

doc.addPage();

y = 0 // Restart height position

}

doc.text(x, y, "value");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值