🚀 Experience the new and improved APIVoid! Check out what's new
A JSON API to convert HTML to a PDF document, plain and simple. Use this API to convert custom HTML to high-quality PDF file, you can set PDF paper size and format (A1, A4, etc) and also "fit" the web page into a one PDF page.
Consumes 20 credits per API call
# Example Curl request from the command line:
curl -X POST "https://api.apivoid.com/v2/html-to-pdf" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY_HERE" \
-d '{"html_base64":"PGh0bWw+PGJvZHk+PGgxPlRlc3RpbmcgSFRNTCB0byBQTkcgQVBJPC9oMT48L2JvZHk+PC9odG1sPg=="}'
# Example JSON output for a 200 HTTP status code:
{
"rendered_file": {
"format": "PDF",
"date_time_utc": "2024-11-29 19:05:01",
"base64_file": "iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAIAAABnsVYUAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3WmYVOWd8OFqa...",
"file_size_readable": "14.73 KB",
"file_size_bytes": 15080
},
"elapsed_ms": 5485
}
Key Features
Businesses and startups use this HTML to PDF API to convert custom HTML code (such as a newsletter template, a HTML template page, a HTML invoice, an so on) into PDF file.
This API can efficiently convert custom HTML code into a PDF (with custom format) document file.
Customize the PDF: set paper size, format (A1, A4, etc), and also "fit" the web page into a one PDF page.
The API will create a high-quality PDF document file of your custom HTML code, you'll love it!
The PDF is generated in 10-20 seconds on average, depends on the complexity of the HTML code.
Common Use Cases
Our API can be used in many ways, from cybersecurity tasks to marketing/research tasks. Here we showcase the most popular use cases according to our customers usage:
Convert custom HTML invoice-like web pages into high-quality PDF for sending to your customers.
Easily convert to PDF any custom HTML code, e.g a web template page or a newsletter template.
Need to rended some HTML code to PDF? Just send it encoded in base64 and wait a few seconds.
Use this API to effortlessly automate any manual task of converting HTML to PDF in no time.
USAGE EXAMPLE
All it takes is a HTTPS POST request with JSON payload to our endpoint, and you’ll receive the response within seconds, usually within 10-20 seconds. Here are a few code examples to use the API:
$html = '<html><body><h1>Testing</h1><p>Example text...</p></body></html>';
$html_base64 = base64_encode($html);
$apiUrl = 'https://api.apivoid.com/v2/html-to-pdf';
$apiKey = 'your_api_key_here';
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'X-API-Key: ' . $apiKey]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['html_base64' => $html_base64]));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$responseData = json_decode($response, true);
print_r($responseData);
// Save the "base64_file" data as PDF file
if (isset($responseData['rendered_file']['base64_file'])) {
$save_as = realpath(dirname(__FILE__)) . "/document.pdf";
file_put_contents($save_as, base64_decode($responseData['rendered_file']['base64_file']));
if (file_exists($save_as)) {
echo '<p>File document.pdf saved successfully.</p>';
} else {
echo '<p>Failed to create document.pdf file.</p>';
}
}
}
Create your account, pick a subscription plan, and make your first API call instantly with your API key—simple as that!
Get started now