node.jspdfpdf-generationphantomjs

How to Generate PDF in node.js


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.

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


Solution

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

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