简体   繁体   English

使用 javascript 将 div 内容导出到 pdf 文件

[英]export div content to a pdf file using javascript

I have some text boxs or form like thing totally enclosed in a div.我有一些文本框或完全包含在 div 中的表单。 I want to provide a option to download that div content as a pdf file on button click and using only javascript.我想提供一个选项,以便在单击按钮时将该 div 内容下载为 pdf 文件并仅使用 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 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.您将无法直接将 div 转换为 PDF 图像,但您将能够一个一个地绘制每个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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