Create Pdf with Div Frame Using jspdf

I am trying to use the JsPdf library to create pdf based on html elements. I want to know if it is possible to do this with the border of the div or if I have to use the doc.line property and essentially draw each line around my div. I.e.

var doc = new jsPDF()

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

I would rather use <div style="border: solid; width: 300px ">

Is anyone lucky with this?

Here is my fiddle

+6
source share
2 answers

How about using jsPdf in conjunction with Html2Canvas? Select html on the canvas, then add the canvas to pdf as an image:

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

See the fiddle for a full example: http://jsfiddle.net/nLLuvnwL/

+3
source

doc.rect . , doc.setLineWidth.

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

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

. http://jsfiddle.net/508p61r6/5/

+1

All Articles