Check this out http://www.techumber.com/2015/04/html-to-pdf-conversion-using-javascript.html
Basically you need to use html2canvas and jspdf to make it work. First you will convert your dom to image and then you will use jspdf to create pdf with the images.
EDIT:
A short note on how it work.
We will use two libraries to make this job done. http://html2canvas.hertzen.com/ and
https://github.com/MrRio/jsPDF
First we will create a dom image by using html2canvas them we will use jspdf addImage method to add that image to pdf.
It seems simple but there are few bugs in jsPdf and html2cavas so you may need to change dom style temporarily.
Hope this helps.
Or,
If you want to print a page as pdf through button action then try this. Using the browser’s Print...
menu item, you can utilize a PDF Printer Driver through code. This way any JavaScript included in the page is processed by the browser when the page is rendered.
<script>
function swapCss() {
window.print();
}
</script>
<input class="printbutton" type="button" onclick="swapCss();" value="Print Customer Copy"/>
2
solved how can i extract text and image in PDF file using php or javascript [closed]