使用window.print内容以pdf格式下载网页 [英] Use window.print content to download a web page as pdf
问题描述
我希望有一个链接,点击时,会自动开始下载网页的可打印版本。
I would like to have a link that when is clicked, automatically starts the download of the printable version of the web page.
我正在使用Moodle。我希望它的内容完全相同如果我使用ctrl + p下载页面并保存为pdf或使用
I'm using Moodle. The content I want it's exactly the same If I download the page using ctrl + p and saving as pdf or using
<a href=\"whatever.htm\" onClick=\"window.print();return false\">Download web page</a>
我想要那个内容,因为使用这种方式,标题,侧边栏和页脚被删除了。我不想要CSS。
I want exactly that content because using this way, the header, sidebar and footer is removed. I don't want css.
我没有使用它,因为这在某些浏览器中不起作用。
I'm not using this because this doesn't work in some browsers.
我宁愿不使用像tcpdf这样的pdf库,因为Moodle以动态方式加载内容并将其发送到像这样的库中。
I'd rather not using pdf libraries like tcpdf because Moodle loads the content in a dynamic way and send this to a libraries like that is a mess.
I尝试使用像pdfcrowd.com这样的网站,但是当你想要转换为pdf的网站使用服务器端会话来识别用户时,这种网站不起作用。
I tried using sites like pdfcrowd.com but this kind of sites don't work when the site you want to convert to pdf uses a server-side session to identify the user.
推荐答案
我不相信有办法用 window.print()
来做到这一点。但是,有免费提供HTML到PDF转换器,您可以自动开始下载。这方面的一个例子是 jsPDF ,这是一个免费的库,用于使用Javascript将HTML转换为PDF
I don't believe that there is a way to do this with window.print()
. However, there are HTML to PDF converters available for free, and you could automatically start a download with that. An example of this would be jsPDF, a free library for converting HTML to a PDF with Javascript
这篇关于使用window.print内容以pdf格式下载网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!