是否可以使用JavaScript或jquery将HTML页面保存为PDF? [英] Is it possible to save HTML page as PDF using JavaScript or jquery?

查看:484
本文介绍了是否可以使用JavaScript或jquery将HTML页面保存为PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用JavaScript或jquery将HTML页面保存为PDF?

Is it possible to save HTML page as PDF using JavaScript or jquery?

详情:

我生成了一个包含表格的HTML页面。它有一个按钮'另存为PDF'。如果用户点击该按钮,则该HTML页面必须转换为PDF文件。

I generated one HTML Page which contains a table . It has one button 'save as PDF'. If user clicks that button then that HTML page has to convert as PDF file.

是否可以使用JavaScript或jquery?

Is it possible using JavaScript or jquery?

推荐答案

,使用 jspdf 创建pdf文件。

Yes, Use jspdf To create a pdf file.

然后,您可以将其转换为数据URI并将下载链接注入DOM

You can then turn it into a data URI and inject a download link into the DOM

然而,您将会需要自己编写HTML到pdf转换。

You will however need to write the HTML to pdf conversion yourself.

只需使用打印机友好版本的页面,让用户选择打印页面的方式。

Just use printer friendly versions of your page and let the user choose how he wants to print the page.

编辑:显然支持率最低

所以答案是编写自己的PDF编写器或获取现有的PDF编写器(在服务器上)。

So the answer is write your own PDF writer or get a existing PDF writer to do it for you (on the server).

这篇关于是否可以使用JavaScript或jquery将HTML页面保存为PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆