In this tutorial, we will show you how to convert a webpage to PDF in JavaScript using PDF.co Web API. Below is the image of Wikipedia’s main page and its PDF version after conversion.

Step 1 – Source Code
First, open the source code in your preferred editor and save it as app.js in a folder. You can get a copy of the source code here.
Step 2 – Add API Key
In line 21, use your PDF.co API Key as the API_Key variable’s value. You can get it here.
Step 3 – Source and Destination File
In line 25, enter the Wikipedia link https://en.wikipedia.org/wiki/Main_Page as the source link and its destination file in line 27.
Step 4 – Run Program
Now, type in node app.js
in the Terminal. Be sure to set the path where the file is stored.
Step 5 – Output File
After the program confirms that the PDF file has been generated, open the folder to see the result.
Step 6 – Webpage to PDF Demo
Here’s the Webpage to PDF in action.

In this tutorial, you learned how to convert a webpage to PDF in JavaScript using PDF.co Web API. You also learned how to set up the PDF.co URL to PDF parameters to get the result right away.