HTML到PDF与Node.js [英] HTML to PDF with Node.js
问题描述
我正在寻找创建一个可打印的 pdf
我的网站网页版本。像 express.render()
只将页面呈现为 pdf
有没有人知道这样做的节点模块?
如果没有,你将如何去实现一个?我已经看到一些方法谈论使用无头浏览器,如 phantom.js
,但不知道流程是什么。
扩展Mustafa的答案。
A)安装
C)这是一个渲染pdf的例子
var phantom = require('phantom');
phantom.create()然后(function(ph){
ph.createPage()。then(function(page){
page.open(http: /www.google.com\").then(function(status){
page.render('google.pdf')。then(function(){
console.log('Page Rendered') ;
ph.exit();
});
});
});
});
PDF的输出:
编辑: 无声打印PDF
java -jar pdfbox-app-2.0.2.jar PrintPDF -silentPrint C:\print_mypdf.pdf
I'm looking to create a printable pdf
version of my website webpages. Something like express.render()
only render the page as pdf
Does anyone know a node module that does that ?
If not, how would you go about implementing one ? I've seen some methods talk about using headless browser like phantom.js
, but not sure whats the flow.
Extending upon Mustafa's answer.
A) Install http://phantomjs.org/ and then
B) install the phantom node module https://github.com/amir20/phantomjs-node
C) Here is an example of rendering a pdf
var phantom = require('phantom');
phantom.create().then(function(ph) {
ph.createPage().then(function(page) {
page.open("http://www.google.com").then(function(status) {
page.render('google.pdf').then(function() {
console.log('Page Rendered');
ph.exit();
});
});
});
});
Output of the PDF:
EDIT: Silent printing that PDF
java -jar pdfbox-app-2.0.2.jar PrintPDF -silentPrint C:\print_mypdf.pdf
这篇关于HTML到PDF与Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!