HTML to PDF API: Generate PDFs from HTML with PDF-API
How to generate PDF files from HTML content
Generating PDF files can be challenging due to the frequent changes in tools and libraries, which can impact your app's performance. An online API like PDF-API eliminates the need to add PDF-related libraries to your apps and allows you to convert HTML content, including web pages, reports with HTML-based charts, and pages with embedded images into PDFs.
Getting started with PDF-API
To generate PDFs from HTML using PDF-API follow these steps:
- Request your API key: Visit pdf-api.co to request your API key. PDF-API is free to use, and your unique API key will be sent to your email.
- Generating PDFs from HTML: Once you have your API key, you can start generating PDF files from HTML content using HTTP requests to one of the API endpoints.
How to generate PDF files using the PDF-API
To generate PDF files using PDF-API, follow these steps:
Access the documentation
Go to pdf-api.co/docs to access the documentation.
Get Your API Key
In the "Get Started" section, provide a valid email address to generate your unique API key.
Make a POST Request
Using the API key and some basic HTML content, make a POST request to pdf-api.co/pdf
pass your API key, the PDF file format (A4/letter), and your HTML content. Here's a CURL example (don't forget to use your own API key):
curl \
-X POST https://pdf-api.co/pdf \
-H 'Content-Type: application/json' \
-d '{
"apiKey": "YOUR_API_KEY",
"format":"A4",
"landscape":false,
"html":"<body>helloworld</body>"
}'
Retrieve your PDF
PDF-API will return the resulting PDF file as a binary file.