You might need to convert a URL to an image, URL to PNG, or automatically take a screenshot of a website for various reasons. Maybe you are crawling websites and would like an image preview of all of them for a database. In either case, if you’re a nodejs developer and you have been doing research, you probably came across Headless Chrome or wkhtmltoimage. Working with either is a headache. Much easier to write just a few lines of code and call it a day. You can easily take a screenshot of a URL with javascript within minutes using our REST API.
Step 1) Open up your package manager and run the command
npm install –save api2pdf
Step 2) Grab an API key from https://portal.api2pdf.com. Only takes 60 seconds.
Step 3) Use the sample code below and replace “YOUR-API-KEY” with the api key you acquired in step 2.
var Api2Pdf = require('api2pdf');
var a2pClient = new Api2Pdf('YOUR-API-KEY');
a2pClient.chromeUrlToImage('https://www.api2pdf.com').then(function(result) { console.log(result); });
And that’s it! Modify the code as you see fit. Hopefully this saves you time and makes converting URLs to images easy and painless for those writing node / javascript code.
We have a whole nodejs based client library for our API that does a lot more than just this. Check out the full library capabilities here: https://github.com/Api2Pdf/api2pdf.node
Tags: puppeteer screenshot javascript, puppeteer screenshot node, url to png api, url to png javascript, url to png node, website screenshot api, website screenshot javascriptComments are closed.