Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Pdf with Div border using jspdf

I am trying to use the JsPdf library to create a pdf based on html elements. 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. I.E.

var doc = new jsPDF()

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

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

Has anyone had any luck with this?

Here is my Fiddle

like image 525
Leonardo Wildt Avatar asked Aug 22 '17 16:08

Leonardo Wildt


1 Answers

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

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/

like image 152
lancew Avatar answered Oct 21 '22 20:10

lancew