簡體   English   中英

使用 javascript 將 div 內容導出到 pdf 文件

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

我有一些文本框或完全包含在 div 中的表單。 我想提供一個選項,以便在單擊按鈕時將該 div 內容下載為 pdf 文件並僅使用 javascript。 請幫我解決這個問題

試試這個代碼

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>

你可以看看這個:

http://parall.ax/products/jspdf

您將無法直接將 div 轉換為 PDF 圖像,但您將能夠一個一個地繪制每個元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM