Best way to generate PDF from a template using nodejs - node.js

Now, I'm looking for the solution to generate pdf (invoice with barcode, etc..) from template(html, css) in nodejs environment. I found there are several ways to do that such as wkhtmltopdf, phantom.js & handlebars.js, html-pdf. What I'm concern is which is the best way to solve this problem.
Also, I have look at jsPDF, an client side generation, but it seem not suitable for production right now.
So, Anyone have used one of these library in production, please give me an advised.
Many thanks !
UPDATED:
Headless chromium is now ready for use.
Have some limitation (e.g: custom header, footer), but work great in almost cases.
https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
UPDATED: 4/2019
Now, Puppeteer is a major library for generating pdfs
https://github.com/GoogleChrome/puppeteer

If the invoice is on a static webpage, PhantomJS will allow you to generate a PDF . Here are a link to the screen-capture section of the docs. It shows you how simple it is do perform this :)

Related

detecting if website has e-commerce in Node.js

I need to detect programatically if a website has an e-commerce platform/system
I don't need to know which one, I just need to know if the website has one.
(I have a big list of websites so I probably need to scrape them)
any suggestions on how I could do this without using external websites (like rescan.io/builtwith/etc) would be greatly appreciated!
thank you!
You can use a package called Puppeteer which is used to do web-scraping in node.js.
I don't know what platforms you are trying to look for, but I guess you could try something like giving the list of websites you want to check to a node.js process and ask Puppeteer to scrape them all. Then you look at the content you get back and for example look for Shopify's CDN in the tags or check the tags for keywords.
You will definitely need to check each different platform like Magento or Shopify for unique source code that clearly sets apart the framework you are looking at from other tools.

NodeJS - PDF generate from URL

Wanted to generate a PDF from a URL
(https://10.1.40.117/print/e71b7c0f-4ed1-4d0d-b868-87418d398a4a).
Please help me with the links which is used to do this using nodeJS
I use Puppeteer to generate PDFs and their documentation has many examples. Since it uses Chrom(e|ium), it closes match my development environment as well which is nice when building the web pages.
For those who might stumble on this question nowadays:
There is cool tool called Gotenberg — Docker-powered stateless API for converting HTML, Markdown and Office documents to PDF. It supports converting URLs via Google Chrome headless.
And I am happen to be an author of JS/TS client for Gotenberg — gotenberg-js-client
I welcome you to use it :)
UPD:
Gotenberg has new website now — https://gotenberg.dev

Hide files in developer tools?

So, I want to apologize ahead of time but I've been googling and stack overflowing for an answer to this question and I just can't find a satisfactory one.
I know that Facebook uses React and, although I don't know what software architecture they use (MVC, Client-Server etc.), I can't see any react files or react components in the dev tools sources tab on any browser.
I'll show you an example in my own react app using create-react-app that shows all my files:
Create-react-apps dev tools sources:
However, when I go to Facebook's page, I don't see anything like that. I see this:
Facebook's dev tools sources:
This isn't only true of react apps, but just node apps I've made as well. Now, I want to know where all of this information is on facebook's page.... Where are the components? Why can't I see them? Where are all the post and get requests being run? How can I put breakpoints in the code for debugging? I mean, I don't even see an HTML page besides the elements tab! And, most importantly, how do I do the same thing to hide my files?
It seems like it adds an extra layer of security that I would think is preferable on all public websites. Once again, thanks in advance and, as far as I know, the answer to this is nowhere near obvious.
I admit, this one little bit confusing when you are quite new on the web development.
You can see your files (source code) via devtool because you also upload your .map files which help map your bundled/minified code into the the original readable one.
However, this is super helpful on development environment, but quite dangerous on production. What you need to do just remove the .map files, as comment suggested.

NodeJS execute flow in background (server side) and grab the html

I am having a website which has many sections and multiple pages in each section.
There is a feature called "Generate PDF" which will traverse through all the sections and pages one by one and grab the HTML from the browser and then generate its PDF. This is working fine as of now.
But this is holding the user from doing anything until the PDF is generated.
I want to have some help on how I can do the same process in background (on server side) ? I have heard from someone that node-curl may help in this but I am not familiar with that.
Can anyone suggest me some ways to proceed further?
If anyone aware about node-curl and just can give hint that it may help me to resolve the issue then also it will be good. I will learn about it and invest my time to get it done.
Or else if someone came across the same kind of problem and have any idea then it will be good.
I am open to use any npm to get it done.
We are also using EmberJs so if any suggestions on that part then also welcomed.
Thank you.
Do you mean you implemented 'Generate PDF' in your client side emberjs code?
If you are running a nodejs based server, you can use node-curl to grab the HTML from intended URL. It is can be risky and you might end up in similar problem of blocking because nodejs runs on single thread. Better you fork a new process to execute 'Generate PDF' logic on separate thread. For details - https://nodejs.org/api/child_process.html

Building a web site with photo uploading possibilities with node.js

I'm new into Node.js and my intention is to build a web site similar (but way less complex) than Imgur, where uploading images is possible by dragging photos from desktop to the browser.
For this I want to use Node.js and MongoDB.
I have been looking around everywhere and found a lots of tutorials (many of them out dated) for setting up a database, but none for file uploading. Node.js and all it's modules is like a jungle, and it really isn't easy to know which modules to use in which type of context.
So, what I really could use here is some help with suggestions of tutorials and/or modules that may fit for this purpose. What is the easiest and best way to get started with this?
This is a school project that I need to do (I selected Node.js for server side myself, not knowing how complex it really is and now it's to late to change), so I would really appreciate your help here.
Thanks in advance!
You can get away without using most of the node.js modules aside from the mongodb driver. Express is a popular framework for web applications, but it might even be overkill here. Really, you just need to serve some HTML with the drag and drop code, and then be able to receive and serve images. It's probably less than 50 lines of code in actual node.js, plus whatever frontend code you have.
Check out this tutorial for the image upload portion on the node.js side using express:
https://github.com/visionmedia/express/blob/master/examples/multipart/app.js
Here's a tutorial for the frontend drag and drop functionality:
http://www.thebuzzmedia.com/html5-drag-and-drop-and-file-api-tutorial/
Update You might also consider http://mongoosejs.com/, which makes mongodb interaction a bit easier--but the native driver isn't too bad to use by itself.

Resources