Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

how How to put and download the content of a div in html into pdf file using JS?

please help. I need to put the content of a div into a pdf file then download it. I've searched a bit and I found that you can use javascript to do this.(jspdf via jsPDF.js)

I found this sample code but it seems that it doesn't work for me. When I click the generate pdf button nothing happens. I am also using codeigniter for my framework and my website is currently uploaded in 000.webhost.com.

 <div id="content"> <h3>Hello, this is a H3 tag</h3> <p>a pararaph</p> </div> <div id="editor"></div> <button id="cmd">generate PDF</button> <script type="text/javascript"> var doc = new jsPDF(); var specialElementHandlers = { '#editor': function (element, renderer) { return true; } }; $('#cmd').click(function () { doc.fromHTML($('#content').html(), 15, 15, { 'width': 170, 'elementHandlers': specialElementHandlers }); doc.save('sample-file.pdf'); }); </script> 

how to put and download the content of a div in html into pdf file?

please help. I need to put the content of a div into a pdf file then download it. I've searched a bit and I found that you can use javascript to do this.(jspdf.js)

I found this sample code but it seems that it doesn't work for me. When I click the generate pdf button nothing happens. I am also using codeigniter for my framework and my website is currently uploaded in 000.webhost.com.

 <div id="content"> <h3>Hello, this is a H3 tag</h3> <p>a pararaph</p> </div> <div id="editor"></div> <button id="cmd">generate PDF</button> <script type="text/javascript"> var doc = new jsPDF(); var specialElementHandlers = { '#editor': function (element, renderer) { return true; } }; $('#cmd').click(function () { doc.fromHTML($('#content').html(), 15, 15, { 'width': 170, 'elementHandlers': specialElementHandlers }); doc.save('sample-file.pdf'); }); </script> 

How to put and download the content of a div in html into pdf file using JS?

I need to put the content of a div into a pdf file then download it. I've searched a bit and I found that you can use javascript to do this via jsPDF.

I found this sample code but it seems that it doesn't work for me. When I click the generate pdf button nothing happens. I am also using codeigniter for my framework and my website is currently uploaded in 000.webhost.com.

 <div id="content"> <h3>Hello, this is a H3 tag</h3> <p>a pararaph</p> </div> <div id="editor"></div> <button id="cmd">generate PDF</button> <script type="text/javascript"> var doc = new jsPDF(); var specialElementHandlers = { '#editor': function (element, renderer) { return true; } }; $('#cmd').click(function () { doc.fromHTML($('#content').html(), 15, 15, { 'width': 170, 'elementHandlers': specialElementHandlers }); doc.save('sample-file.pdf'); }); </script> 
Source Link

how to put and download the content of a div in html into pdf file?

please help. I need to put the content of a div into a pdf file then download it. I've searched a bit and I found that you can use javascript to do this.(jspdf.js)

I found this sample code but it seems that it doesn't work for me. When I click the generate pdf button nothing happens. I am also using codeigniter for my framework and my website is currently uploaded in 000.webhost.com.

 <div id="content"> <h3>Hello, this is a H3 tag</h3> <p>a pararaph</p> </div> <div id="editor"></div> <button id="cmd">generate PDF</button> <script type="text/javascript"> var doc = new jsPDF(); var specialElementHandlers = { '#editor': function (element, renderer) { return true; } }; $('#cmd').click(function () { doc.fromHTML($('#content').html(), 15, 15, { 'width': 170, 'elementHandlers': specialElementHandlers }); doc.save('sample-file.pdf'); }); </script>