2013-12-17 22:39
浏览 1.2k


I would like to have a link that when is clicked, automatically starts the download of the printable version of the web page.

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>

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.

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 tried using sites like 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.

图片转代码服务由CSDN问答提供 功能建议

我想有一个链接点击时,会自动开始下载网页的可打印版本 。

我正在使用Moodle。 我希望它的内容完全相同如果我使用ctrl + p下载页面并保存为pdf或使用

 &lt; a href = \“whatever.htm \”onClick  = \“window.print();返回false \”&gt;下载网页&lt; / a&gt; 

我想要那个内容,因为使用这种方式, 标题,侧边栏和页脚已删除。 我不想要CSS。


我不想 使用像tcpdf这样的pdf库,因为Moodle以动态的方式加载内容并将其发送到类似的库中。

我尝试使用像pdfcrowd.com这样的网站但这种网站 当您要转换为pdf的站点使用服务器端会话来识别用户时,不起作用。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanhuanzhi6431 2013-12-17 22:42

    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

    打赏 评论
  • dongnai1876 2019-04-10 09:00

    **There is easy ways to use jsPDF its very simple just you will use JSpdf Library **

    <script src=""></script>
    function onClick() {
      var pdf = new jsPDF('p', 'pt', 'letter');
      pdf.canvas.height = 72 * 11;
      pdf.canvas.width = 72 * 8.5;
    var element = document.getElementById("clickbind");
    element.addEventListener("click", onClick);
    打赏 评论

相关推荐 更多相似问题