简体   繁体   English

有什么方法可以将HTML页面的数据导出为PDF?

[英]Is there any way to export the html page's data into PDF?

I have an html page which contains multiple selectboxes, labels, input fields and checkboxes. 我有一个html页面,其中包含多个选择框,标签,输入字段和复选框。
I want to export entire html page into PDF. 我想将整个HTML页面导出为PDF。 is there any way I can do so? 有什么办法可以做到吗? Any javascript or library for exporting HTML into PDF ? 是否有library for exporting HTML into PDF javascriptlibrary for exporting HTML into PDF

If you absolutely need to do generate your PDF using Javascript, you can use JsPDF : 如果绝对需要使用Javascript生成PDF,则可以使用JsPDF

var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'Do you like that?');

// Output as Data URI
doc.output('datauri');

But you will have to recreate your html page with the library's syntaxe. 但是您将不得不使用库的语法重新创建html页面。

If generating your document don't necessary have to be done with Javascript, a better way would be to use a php library. 如果不必使用Javascript来生成文档,则更好的方法是使用php库。

In the past I used (DomPdf)[https://github.com/dompdf/dompdf] : very powerfull. 过去我使用(DomPdf)[https://github.com/dompdf/dompdf]:非常强大。 It just take a HTML/CSS document and create a PDF version of it. 它只需要一个HTML / CSS文档并创建一个PDF版本。

If you absolutely need a non-refresh loading, you can use Ajax to generate the document. 如果您绝对需要非刷新加载,则可以使用Ajax生成文档。

尝试一下JsPDF: http ://jspdf.com/ :)问候!

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

相关问题 将 HTML 页面导出到 angular 中的 pdf - Export HTML page to pdf in angular 有什么方法可以将HTML数据和Graph数据都转储为pdf? - Is there any way to dump both HTML data and Graph data into a pdf? 有没有办法将当前呈现的 angular 页面连同所有 JS 功能一起导出到 static HTML ? - Is there any way to export the current rendered angular page to static HTML along with all the JS functionalities? 有没有办法像真正的 html 元素一样呈现 pdf.js 页面而不是 canvas 或 ZAE8EB96DF05E788AC39883A822C7A53EZ 元素 - is there any way to render pdf.js page like real html elements not canvas or svg? 有没有办法通过导出功能传递数据? - Is there an any way to pass data through export functions? 将多页html导出为单个pdf - Export more than one page html to single pdf 使用javascript将html页面导出为密码加密的pdf - export html page as password encrypted pdf using javascript 如何使用JavaScript或jQuery将html页面导出到客户端的pdf? - How to export a html page to pdf in client side using JavaScript or jQuery? 使用JSPdf生成将整个html页面导出为pdf - Export whole html page to pdf using JSPdf generation 使用JavaScript在用户点击时将HTML页面导出为PDF - Export HTML page to PDF on user click using JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM