Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

HTML to PDF with Node.js

HTML to PDF with Node.js


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.

Problem courtesy of: Michael


Extending upon Mustafa's answer.

A) Install and then

B) install the phantom node module

C) Here is an example of rendering a pdf

var phantom = require('phantom');   

phantom.create().then(function(ph) {
    ph.createPage().then(function(page) {"").then(function(status) {
            page.render('google.pdf').then(function() {
                console.log('Page Rendered');

Output of the PDF:

EDIT: Silent printing that PDF

java -jar pdfbox-app-2.0.2.jar PrintPDF -silentPrint C:\print_mypdf.pdf

Solution courtesy of: Jozzhart


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

HTML to PDF with Node.js


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription