Blog

Back to blog posts

Convert HTML to Image or URL to Image with Headless Chrome

Published Oct 25, 2020

Convert HTML to Image or URL to Image with Headless Chrome

Headless Chrome provides a great way to take screenshots or images of raw HTML or a URL of a website. If you need to do this at scale with an easy to use API, we’ve got you covered. We provide a super simple API that allows you to generate these website screenshots with a single POST or GET request.

Simple GET request for URL to Image

If you are looking for the most basic, path of least resistance approach to grabbing screenshots of websites, it is probably easiest to use our GET request.

Make a GET request to the following URL, and replace the {UrlToConvert} and {YourApiKey} with the url to the website you want a screenshot of and your api2pdf.com API key respectively. If you need an API key, you can grab it here.

https://v2.api2pdf.com/chrome/image/url?url={UrlToConvert}&apikey={YourApiKey}

HTML to Image

If you are looking to pass in HTML and convert that to an image, you can make a POST call to

https://v2.api2pdf.com/chrome/image/html

with the following headers:

authorization: YOUR-API-KEY

accept: application/json

and json payload:

{ “html”: “<p>Hello World</p>” }

We offer so many more options as the API is built on top of puppeteer. Check out the full documentation here:

https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/2.0.0-beta