Generate a PDF from HTML with puppeteer

In this post, we gonna use Puppeteer to generate PDF files from HTML. With Puppeteer we can also generate screenshots. What is Puppeteer? The documentation says:

Puppeteer is a Node library that provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default but can be configured to run full (non-headless) Chrome or Chromium.

In this tutorial, we will use the following npm module –
express – A Node.js based web framework
body-parser – Node.js body parsing middleware.
puppeteer – Puppeteer is a Node library which provides a high-level API to control Chrome

Let’s create a folder for the project and initialize it, by running npm init.

you will see the similar output in your terminal

install project dependencies

Create a express server

create a file called index.js in the project root folder with below code.

Now run the application, with node index.js and once it is up you can access the app as shown below

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments Protection Status
Would love your thoughts, please comment.x