Tuesday 14 February 2017

[Beginner] Generate a pdf with node

Hi reddit,I discovered nodejs a few days ago and I'm a total beginner. Actually, I use it mainly for downloading libraries using bower or similar tasks.These days, I'm trying to build my first app with node but I'm stuck.To sum up, my app is an online text editor that use angular to dynamically generate document. The thing is I would like to be able to save my document as a pdf without using ctrl+P , as I use some styling that are unsupported by most browsers. I would like to use prince, which is a software that allows me to generate pdf from an html file. Here is a link to a node module I found.After a few hours, I managed to make it works somehow by creating this file that is named pdf.js:var Prince = require("prince"); Prince() .inputs("mydocument.html") .output("test.pdf") .execute() .then(function () { console.log("OK: done"); }, function (error) { console.log("ERROR: ", util.inspect(error)); }) When I want to generate the pdf, I open a command line and type node pdf.js and it does its magic.That's a first step and it works locally, with a static html but Ideally, I would like to be able to click on a button and make node generate this pdf with the content displayed on the browser.Here is what I have at the moment:
To sum up, here is what I want to do:Send the dynamically generated content displayed on the browser to be converted to pdfTrigger a node action when clicking on a buttonSend the generated document back to the browser to be downloadedI hope my problem is clear enough!Thanks a lot for your help on this issue and let me know if I can give more information!

Submitted February 14, 2017 at 03:46PM by petrarco123

No comments:

Post a Comment