curl
curl --request POST \
--url https://api.iyzpdf.com/v1/convert/html-to-pdf \
--header "X-API-Key: $IYZPDF_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"html": "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
"options": {
"format": "A4",
"marginTop": "2cm",
"marginBottom": "2cm",
"printBackground": true
}
}' \
--output invoice.pdfimport os
import requests
api_key = os.environ["IYZPDF_API_KEY"]
payload = {
"html": "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
"options": {
"format": "A4",
"marginTop": "2cm",
"marginBottom": "2cm",
"printBackground": True,
},
}
response = requests.post(
"https://api.iyzpdf.com/v1/convert/html-to-pdf",
headers={"X-API-Key": api_key},
json=payload,
timeout=60,
)
if not response.ok:
raise Exception(response.text)
with open("invoice.pdf", "wb") as output_file:
output_file.write(response.content)import { writeFile } from "node:fs/promises";
const apiKey = process.env.IYZPDF_API_KEY;
const payload = {
html: "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
options: {
format: "A4",
marginTop: "2cm",
marginBottom: "2cm",
printBackground: true
}
};
const response = await fetch("https://api.iyzpdf.com/v1/convert/html-to-pdf", {
method: "POST",
headers: {
"X-API-Key": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(await response.text());
}
const fileBuffer = Buffer.from(await response.arrayBuffer());
await writeFile("invoice.pdf", fileBuffer);<?php
$apiKey = getenv('IYZPDF_API_KEY');
$payload = [
'html' => '<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>',
'options' => [
'format' => 'A4',
'marginTop' => '2cm',
'marginBottom' => '2cm',
'printBackground' => true,
],
];
$ch = curl_init('https://api.iyzpdf.com/v1/convert/html-to-pdf');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$pdf = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($pdf === false || $status !== 200) {
throw new RuntimeException('Request failed: ' . curl_error($ch) . PHP_EOL . $pdf);
}
file_put_contents('invoice.pdf', $pdf);
curl_close($ch);import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
public class HtmlToPdfExample {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("IYZPDF_API_KEY");
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"html": "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
"options": {
"format": "A4",
"marginTop": "2cm",
"marginBottom": "2cm",
"printBackground": true
}
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.iyzpdf.com/v1/convert/html-to-pdf"))
.header("X-API-Key", apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
if (response.statusCode() != 200) {
throw new RuntimeException("Request failed with status " + response.statusCode());
}
Files.write(Path.of("invoice.pdf"), response.body());
}
}using System.Net.Http.Json;
var apiKey = Environment.GetEnvironmentVariable("IYZPDF_API_KEY");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
var payload = new
{
html = "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
options = new
{
format = "A4",
marginTop = "2cm",
marginBottom = "2cm",
printBackground = true
}
};
using var response = await client.PostAsJsonAsync(
"https://api.iyzpdf.com/v1/convert/html-to-pdf",
payload);
response.EnsureSuccessStatusCode();
await using var output = File.Create("invoice.pdf");
await response.Content.CopyToAsync(output);{
"fileName": "output.pdf",
"size": 183240,
"creditsUsed": 1,
"creditsRemaining": 49,
"contentType": "application/pdf"
}{
"error": {
"code": "INVALID_REQUEST",
"message": "The request payload is invalid or incomplete."
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing or invalid API key."
}
}{
"error": {
"code": "INSUFFICIENT_CREDITS",
"message": "You need more credits to complete this request.",
"creditsRequired": 2,
"creditsBalance": 0,
"purchaseUrl": "https://iyzpdf.com/portal/credits"
}
}{
"error": {
"code": "SSRF_BLOCKED",
"message": "Private or internal URLs are not allowed."
}
}{
"error": {
"code": "FILE_TOO_LARGE",
"message": "The uploaded file or request body exceeds the allowed size limit."
}
}{
"error": {
"code": "UNSUPPORTED_MEDIA_TYPE",
"message": "The uploaded file type or content type is not supported."
}
}{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please retry after the rate limit resets."
}
}{
"error": {
"code": "PROCESSING_FAILED",
"message": "The document could not be processed."
}
}Conversion
HTML To PDF
Render inline HTML, uploaded HTML files, or public URLs into PDF.
POST
https://api.iyzpdf.com/v1
/
convert
/
html-to-pdf
curl
curl --request POST \
--url https://api.iyzpdf.com/v1/convert/html-to-pdf \
--header "X-API-Key: $IYZPDF_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"html": "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
"options": {
"format": "A4",
"marginTop": "2cm",
"marginBottom": "2cm",
"printBackground": true
}
}' \
--output invoice.pdfimport os
import requests
api_key = os.environ["IYZPDF_API_KEY"]
payload = {
"html": "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
"options": {
"format": "A4",
"marginTop": "2cm",
"marginBottom": "2cm",
"printBackground": True,
},
}
response = requests.post(
"https://api.iyzpdf.com/v1/convert/html-to-pdf",
headers={"X-API-Key": api_key},
json=payload,
timeout=60,
)
if not response.ok:
raise Exception(response.text)
with open("invoice.pdf", "wb") as output_file:
output_file.write(response.content)import { writeFile } from "node:fs/promises";
const apiKey = process.env.IYZPDF_API_KEY;
const payload = {
html: "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
options: {
format: "A4",
marginTop: "2cm",
marginBottom: "2cm",
printBackground: true
}
};
const response = await fetch("https://api.iyzpdf.com/v1/convert/html-to-pdf", {
method: "POST",
headers: {
"X-API-Key": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(await response.text());
}
const fileBuffer = Buffer.from(await response.arrayBuffer());
await writeFile("invoice.pdf", fileBuffer);<?php
$apiKey = getenv('IYZPDF_API_KEY');
$payload = [
'html' => '<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>',
'options' => [
'format' => 'A4',
'marginTop' => '2cm',
'marginBottom' => '2cm',
'printBackground' => true,
],
];
$ch = curl_init('https://api.iyzpdf.com/v1/convert/html-to-pdf');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$pdf = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($pdf === false || $status !== 200) {
throw new RuntimeException('Request failed: ' . curl_error($ch) . PHP_EOL . $pdf);
}
file_put_contents('invoice.pdf', $pdf);
curl_close($ch);import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
public class HtmlToPdfExample {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("IYZPDF_API_KEY");
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"html": "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
"options": {
"format": "A4",
"marginTop": "2cm",
"marginBottom": "2cm",
"printBackground": true
}
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.iyzpdf.com/v1/convert/html-to-pdf"))
.header("X-API-Key", apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
if (response.statusCode() != 200) {
throw new RuntimeException("Request failed with status " + response.statusCode());
}
Files.write(Path.of("invoice.pdf"), response.body());
}
}using System.Net.Http.Json;
var apiKey = Environment.GetEnvironmentVariable("IYZPDF_API_KEY");
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
var payload = new
{
html = "<!doctype html><html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
options = new
{
format = "A4",
marginTop = "2cm",
marginBottom = "2cm",
printBackground = true
}
};
using var response = await client.PostAsJsonAsync(
"https://api.iyzpdf.com/v1/convert/html-to-pdf",
payload);
response.EnsureSuccessStatusCode();
await using var output = File.Create("invoice.pdf");
await response.Content.CopyToAsync(output);{
"fileName": "output.pdf",
"size": 183240,
"creditsUsed": 1,
"creditsRemaining": 49,
"contentType": "application/pdf"
}{
"error": {
"code": "INVALID_REQUEST",
"message": "The request payload is invalid or incomplete."
}
}{
"error": {
"code": "UNAUTHORIZED",
"message": "Missing or invalid API key."
}
}{
"error": {
"code": "INSUFFICIENT_CREDITS",
"message": "You need more credits to complete this request.",
"creditsRequired": 2,
"creditsBalance": 0,
"purchaseUrl": "https://iyzpdf.com/portal/credits"
}
}{
"error": {
"code": "SSRF_BLOCKED",
"message": "Private or internal URLs are not allowed."
}
}{
"error": {
"code": "FILE_TOO_LARGE",
"message": "The uploaded file or request body exceeds the allowed size limit."
}
}{
"error": {
"code": "UNSUPPORTED_MEDIA_TYPE",
"message": "The uploaded file type or content type is not supported."
}
}{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please retry after the rate limit resets."
}
}{
"error": {
"code": "PROCESSING_FAILED",
"message": "The document could not be processed."
}
}Notes
- Credits:
1for inline HTML or file upload,2for URL mode - Use either
htmlorurl, never both - URL mode only supports public
httpandhttpsaddresses - Private or internal URLs are rejected
- Authenticated HTML payloads and HTML uploads are limited to
10 MB
Authorizations
Send your server-side API key in the X-API-Key header.
Body
application/jsonmultipart/form-data