简体   繁体   English

使用jspdf创建具有Div边框的Pdf

[英]Create Pdf with Div border using jspdf

I am trying to use the JsPdf library to create a pdf based on html elements. 我正在尝试使用JsPdf库基于html元素创建pdf。 I am wanting to know if it is possible to do with a div border or if i have to use the doc.line property and essentially draw each line around my div. 我想知道是否可以使用div边框,或者我是否必须使用doc.line属性并实质上在div周围绘制每条线。 IE IE浏览器

var doc = new jsPDF()

doc.line(20, 20, 60, 20)

I would much rather use <div style="border: solid; width: 300px "> 我宁愿使用<div style="border: solid; width: 300px ">

Has anyone had any luck with this? 有人有运气吗?

Here is my Fiddle 这是我的小提琴

How about using jsPdf in conjunction with Html2Canvas? 如何将jsPdf与Html2Canvas结合使用? Render the html to canvas, then add the canvas to the pdf as an image like so: 将html渲染到画布上,然后将画布作为图像添加到pdf中,如下所示:

var img = canvas.toDataURL("image/png");
doc.addImage(img, 'JPEG', 300, 200);
doc.save('test.pdf');

See fiddle for full example: http://jsfiddle.net/nLLuvnwL/ 有关完整示例,请参见小提琴: http : //jsfiddle.net/nLLuvnwL/

Instead of drawing each lines you can use doc.rect to draw the rectangle. 您可以使用doc.rect绘制矩形来代替绘制每条线。 You can also change the border width using doc.setLineWidth . 您也可以使用doc.setLineWidth更改边框宽度。

doc.setLineWidth(2);
doc.rect(10, 20, 150, 75);

doc.save('sample-file.pdf');

See example here http://jsfiddle.net/508p61r6/5/ 在这里查看示例http://jsfiddle.net/508p61r6/5/

for (var i=1;i<pdf.internal.pages.length;i++){
pdf.internal.pages[i].push("0.00 595.28 841.89 -595.28 re");
pdf.internal.pages[i].push("S");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM