Javascript:网页的PDF导出按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16099277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript: PDF export button for webpage
提问by saiyan101
I would like any pointers or resources to where I can get a java-script that allows my export button on my site to export my current page to pdf.
我想要任何指向我可以获得 java 脚本的指针或资源,该脚本允许我的网站上的导出按钮将我的当前页面导出为 pdf。
回答by SWilk
I think there is no javascript library which would allow to create a pdf file. Mozilla implemented complete PDF reader in js and includes it in latest Firefox, but that is huge library. EDIT: there is jspdf which seems to be able to do that.
我认为没有允许创建 pdf 文件的 javascript 库。Mozilla 在 js 中实现了完整的 PDF 阅读器,并将其包含在最新的 Firefox 中,但这是一个巨大的库。编辑:有 jspdf 似乎能够做到这一点。
I think you should go with server side PDF engine.
我认为您应该使用服务器端 PDF 引擎。
DOMPdf is a PHP library which allows to render complete HTML with CSS, images etc to PDF document. It even has a example php script which put on server allows to convert submited html to PDF.
DOMPdf 是一个 PHP 库,它允许将带有 CSS、图像等的完整 HTML 呈现为 PDF 文档。它甚至有一个放在服务器上的示例 php 脚本,允许将提交的 html 转换为 PDF。
Your javascript "button" should just get the document.getElementsByTagName('html')[0].innerHTML and post that HTML to the DOMPdf script. You should get more or less correct PDF out of this.
您的 javascript“按钮”应该只获取 document.getElementsByTagName('html')[0].innerHTML 并将该 HTML 发布到 DOMPdf 脚本。您应该从中获得或多或少正确的 PDF。
回答by SWilk
Follow the Link of Zend_Pdf : http://framework.zend.com/manual/1.12/en/zend.pdf.html
按照 Zend_Pdf 的链接:http: //framework.zend.com/manual/1.12/en/zend.pdf.html
You can also try jspdf : http://jspdf.com/
你也可以试试 jspdf :http://jspdf.com/
回答by Hariharan
i unable to get your requirement, i hope you require to take pdf of web page.
我无法得到您的要求,我希望您需要获取网页的 pdf。
if my understanding is correct, Please refer below link
如果我的理解正确,请参考以下链接
http://www.hiqpdf.com/demo/ConvertHtmlToPdf.aspx
http://www.hiqpdf.com/demo/ConvertHtmlToPdf.aspx
also see the existing post ITextSharp HTML to PDF?
还看到现有的帖子ITextSharp HTML to PDF?
Thanks
谢谢
回答by Ankit
Use wkhtmltopdffor this purpose. I am using it to generate pdf of html pages.
为此目的使用wkhtmltopdf。我正在使用它来生成 html 页面的 pdf。
But it is not possible alone with javascript. You have to have some server side code for the same.
但是单独使用 javascript 是不可能的。你必须有一些相同的服务器端代码。