简体   繁体   English

使用nodejs将html转换为pdf

[英]convert html into pdf using nodejs

I am newbie in web development. 我是网络开发的新手。 I have a html page where there is some article having text and some pictures. 我有一个html页面,其中有一些文章包含文字和图片。 I want to make the content of that html page into pdf and download it using "download as pdf" button. 我想将该html页面的内容转换为pdf,然后使用“以pdf格式下载”按钮下载。 How can convert the html page into pdf and download that page using nodejs. 如何将html页面转换为pdf并使用nodejs下载该页面。 A sample code or demonstration will be great help. 示例代码或演示将有很大帮助。

A general solution to what you are asking for is to use a headless browser, like PhantomJS , running on your backend to render the requested page, then export it as a PDF, before finally stream it to user's download request. 一种通用的解决方案是使用无头浏览器(例如PhantomJS )在后端运行,以呈现请求的页面,然后将其导出为PDF,最后将其流式传输到用户的下载请求。

An example on how to render and export a webpage to PDF can be found here . 此处可以找到有关如何将网页呈现和导出为PDF的示例。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM