如何在node.js中生成PDF [英] How to Generate PDF in node.js

查看:685
本文介绍了如何在node.js中生成PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成一个模块,该模块将输入作为我的发票来生成PDF,并且该PDF文件会自动发送给客户邮件ID.在第一步中,我得到了一些代码,并尝试生成PDF.该代码可以正常工作,并且我能够生成PDF.但是我无法打开文件.

I want to generate a module which will generate PDF by taking input as my Invoice and that PDF file is send to clients mail id automatic. In 1st step i got some code and try to generate PDF. That code is working fin and i am able to generate the PDF. but i am not able to open the file.

对于代码,我使用此链接: http://github.com/marak/pdf.js/

for code i use this link:http://github.com/marak/pdf.js/

推荐答案

安装 http://phantomjs.org/并安装幻像节点模块 https://github.com/amir20/phantomjs-node

Install http://phantomjs.org/ and the install the phantom node module https://github.com/amir20/phantomjs-node

这里是渲染pdf的示例

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();
            });
        });
    });
});

这篇关于如何在node.js中生成PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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