简体   繁体   中英

export div content to a pdf file using javascript

I have some text boxs or form like thing totally enclosed in a div. I want to provide a option to download that div content as a pdf file on button click and using only javascript. Plz help me to solve this

try this code

function printChart() {
                pvwindow = window.open('', 'PrintWindow', ' location = 0, status = 0,  scrollbars = 1, width = 750, height = 600')
                pvwindow.document.write("<html>");
                pvwindow.document.write("<head>");
                pvwindow.document.write("</head>");
                pvwindow.document.write("<body   style='background-color:white;' onload='window.print();'>");
                pvwindow.document.write(document.getElementById("print_div").innerHTML);
                pvwindow.document.write("</body>");
                pvwindow.document.write("</html>");
                pvwindow.document.close();
            }
</script>

You can have a look at this:

http://parall.ax/products/jspdf

You will not be able to convert a div into a PDF image directly, but you will be able to draw each elements one by one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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