[英]How to export a html page to pdf in client side using JavaScript or jQuery?
And if it is not possible then what are the other alternatives? 如果不可能,那么其他选择是什么?
I tried to convert a complete html page to pdf with dynamic values but I can't . 我尝试将完整的html页面转换为动态值的pdf,但我不能。
But I saw some API like jspdf but it is not useful for me. 但我看到了一些像jspdf这样的API,但它对我没用 。
Is it possible to save a HTML page as PDF file using JavaScript or jQuery? 是否可以使用JavaScript或jQuery将HTML页面保存为PDF文件?
In Detail: 详细:
I generated one HTML Page which contains a list grid which populated all the available reports dynamically. 我生成了一个HTML页面,其中包含一个列表网格,可以动态填充所有可用的报告。 It has one button 'save as PDF'. 它有一个按钮'另存为PDF'。 If the user clicks this button then the HTML page will be converted to a PDF file. 如果用户单击此按钮,则HTML页面将转换为PDF文件。
Is it possible using JavaScript or jquery? 是否可以使用JavaScript或jquery?
jsPDF has a HTML renderer but it is in the early stages: jsPDF有一个HTML渲染器,但它处于早期阶段:
https://github.com/mrrio/jsPDF https://github.com/mrrio/jsPDF
http://parall.ax/products/jspdf http://parall.ax/products/jspdf
But the best solution is the one from mujaffars. 但最好的解决方案是来自mujaffars的解决方案。 User AJAX and a stable PDF library written in PHP like FPDF, PDFLib, TCPDF and others 用户AJAX和用PHP编写的稳定的PDF库,如FPDF,PDFLib,TCPDF等
Well, if I have got your question properly then u need to Export a Table Data as PDF
? 那么,如果我有正确的问题,那么你需要将Export a Table Data as PDF
吗?
If Yes, then please see datatables.js with simple example here . 如果是,那么请在这里看一下带有简单示例的datatables.js 。
Also, look into use BytescoutPDF.js (Bytescout PDF Generator for JavaScript) to draw PDF invoice and JSPDF you can get the details here . 另外,请使用BytescoutPDF.js(Bytescout PDF Generator for JavaScript)绘制PDF发票和JSPDF,您可以在此处获取详细信息。
You need to use any pdf generating library. 您需要使用任何pdf生成库。 You have not specified in which technology you are working (Php, .net or anything else) 您尚未指定您使用的技术(Php,.net或其他)
In PHP you can use tcpdf library, Where you can pass html to generate pdf 在PHP中,您可以使用tcpdf库,您可以在其中传递html以生成pdf
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
$pdf->writeHTML($pdfHtml, true, false, true, false, '');
Where $pdfHtml will be your page html $ pdfHtml将成为你的页面html
In your case when clicking on 'save as pdf' button you can get html by using html() method of jquery 在您点击“另存为pdf”按钮的情况下,您可以使用jquery的html()方法获取html
eg. 例如。
var pageHtml = $('html').html();
by passing pageHtml to ajax page, You can create pdf in ajax page 通过将pageHtml传递给ajax页面,您可以在ajax页面中创建pdf
It is possible indeed with pdf.js
plugin pdf.js
is an HTML5 experiment that explores building a faithful and efficient PDF renderer without native code assistance. 有可能使用pdf.js
插件pdf.js
是一个HTML5实验,探索构建一个忠实而有效的PDF渲染器,而无需本机代码帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.