Generate PDF from Cloudflare Worker with Headless Chrome

January 9th, 2022 / by api2pdf /

Intro

At the time of this post, Cloudflare Workers does not support the idea of embedding Headless Chrome or wkhtmltopdf in its environment. Workers also does not the idea of running docker containers either. This may change in the future, but for now, if you built an application on top of workers and need to generate a PDF file, you’re kind of stuck.

REST API

API2PDF will easily work with Cloudflare Workers because we provide a REST API that you can call from your workers to generate the PDF. We run Headless Chrome behind the scenes and you can convert HTML to PDF or a URL to PDF. We also offer other commands such as merging PDFs together, screenshots of URLs, HTML to Docx, Office files to PDF, and thumbnailing PDFs / Office files.

All you need to get started is an API key which you can grab for free here: https://portal.api2pdf.com/register

Sample Code

Below you will find sample code that you can modify to create a Cloudflare Worker. Replace apiKey variable with the API key you acquired from above.

Full on documentation is available at https://www.api2pdf.com/documentation

 

Tags: , , , , , , , , , ,

Comments are closed.