HTML2PDFAPI is a powerful REST API that converts HTML content and URLs into PDFs, screenshots, and videos using cloud-based Chromium rendering.
Convert HTML or URLs to high-quality PDF documents with full CSS support
Capture PNG, JPEG, or WebP screenshots of any webpage or HTML content
Record MP4 videos of webpage interactions and animations
Cloud-based Chromium rendering with automatic scaling and high availability
API key authentication, HTTPS encryption, and optional S3 integration
7-day default retention or bring your own S3 bucket for full control
Base URL
https://html2pdfapi.comAll API requests require authentication. Include your API key in the request body. Get your API key from your dashboard.
{
"apiKey": "YOUR_API_KEY",
"html": "<h1>Hello</h1>",
"format": "pdf"
}Keep your API key secure. Never expose it in client-side code or public repositories.
Convert HTML to PDF with a single API call:
curl -X POST https://html2pdfapi.com/api/render \
-H "Content-Type: application/json" \
-d '{
"apiKey": "YOUR_API_KEY",
"html": "<h1>Hello World</h1>",
"format": "pdf"
}'const response = await fetch('https://html2pdfapi.com/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
apiKey: 'YOUR_API_KEY',
html: '<h1>Hello World</h1>',
format: 'pdf'
})
});
const data = await response.json();
console.log(data);import requests
response = requests.post(
'https://html2pdfapi.com/api/render',
json={
'apiKey': 'YOUR_API_KEY',
'html': '<h1>Hello World</h1>',
'format': 'pdf'
}
)
print(response.json())const fetch = require('node-fetch');
const response = await fetch('https://html2pdfapi.com/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
apiKey: 'YOUR_API_KEY',
html: '<h1>Hello World</h1>',
format: 'pdf'
})
});
const data = await response.json();
console.log(data);Or convert a URL to PDF:
curl -X POST https://html2pdfapi.com/api/render \
-H "Content-Type: application/json" \
-d '{
"apiKey": "YOUR_API_KEY",
"url": "https://example.com",
"format": "pdf",
"pdf": {
"format": "A4",
"printBackground": true
}
}'const response = await fetch('https://html2pdfapi.com/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
apiKey: 'YOUR_API_KEY',
url: 'https://example.com',
format: 'pdf',
pdf: {
format: 'A4',
printBackground: true
}
})
});
const data = await response.json();import requests
response = requests.post(
'https://html2pdfapi.com/api/render',
json={
'apiKey': 'YOUR_API_KEY',
'url': 'https://example.com',
'format': 'pdf',
'pdf': {
'format': 'A4',
'printBackground': True
}
}
)const fetch = require('node-fetch');
const response = await fetch('https://html2pdfapi.com/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
apiKey: 'YOUR_API_KEY',
url: 'https://example.com',
format: 'pdf',
pdf: {
format: 'A4',
printBackground: true
}
})
});Provide content using one of:
html Raw HTML contenturl URL to captureSet format to:
Capture a full-page screenshot at a specific viewport size:
curl -X POST https://html2pdfapi.com/api/render \
-H "Content-Type: application/json" \
-d '{
"apiKey": "YOUR_API_KEY",
"url": "https://example.com",
"format": "png",
"render": {
"fullPage": true
},
"device": {
"width": 1920,
"height": 1080
}
}'const response = await fetch('https://html2pdfapi.com/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
apiKey: 'YOUR_API_KEY',
url: 'https://example.com',
format: 'png',
render: {
fullPage: true
},
device: {
width: 1920,
height: 1080
}
})
});import requests
response = requests.post(
'https://html2pdfapi.com/api/render',
json={
'apiKey': 'YOUR_API_KEY',
'url': 'https://example.com',
'format': 'png',
'render': {
'fullPage': True
},
'device': {
'width': 1920,
'height': 1080
}
}
)render.fullPage Capture the entire scrollable page, not just the viewport
render.waitTime Wait for a specified time (ms) after page load before capture
device.width/height Set the viewport dimensions in pixels
pdf.printBackground Include background colors and images in PDF output
render.block Block ads, trackers, cookies, and banners during render
Complete reference for all API endpoints and parameters.
/api/render/api/render/:idConvert HTML content or a URL to PDF, image, or video.
apiKeyYour API key for authentication
formatOutput format
pdfpngjpegwebpvideohtmlRaw HTML content to render (use html OR url, not both)
urlURL of the webpage to capture (use url OR html, not both)
render.fullPageCapture the full scrollable page
render.waitTimeWait time after page load (ms)
render.timeoutRendering timeout (ms)
render.waitUntilPage load event to wait for
networkidle0domcontentloadedloadnetworkidle2render.triggerLazyAnimationsTrigger lazy animations before capture
render.blockBlock specific content types
.cookies (boolean) - Block cookies.ads (boolean) - Block ads.trackers (boolean) - Block trackers.banners (boolean) - Block bannersrender.scrollScroll behavior options
.position (integer) - Scroll position (px).animate (boolean) - Animate scrolling.duration (integer) - Animation duration (ms)device.widthViewport width (px)
device.heightViewport height (px)
device.deviceScaleFactorDevice scale factor (DPR)
device.userAgentCustom user agent string
device.localeBrowser locale
device.timezoneBrowser timezone
device.cacheEnable caching
device.cacheKeyCustom cache key
pdf.formatPage format
LetterLegalTabloidLedgerA0A1A2A3A4A5A6pdf.widthPage width (px)
pdf.heightPage height (px)
pdf.scaleScale of the webpage rendering
pdf.landscapeLandscape orientation
pdf.printBackgroundPrint background graphics
pdf.displayHeaderFooterDisplay header and footer
pdf.headerTemplateHTML template for header
pdf.footerTemplateHTML template for footer
pdf.pageRangesPage ranges to print (e.g. "1-5")
pdf.marginPage margins
.top (string) - Top margin.right (string) - Right margin.bottom (string) - Bottom margin.left (string) - Left marginpdf.preferCSSPageSizePrefer CSS page size
pdf.omitBackgroundOmit background
image.typeImage format
pngjpegwebpgifavifimage.qualityImage quality (0-100, for jpeg/webp)
image.compressionCompression level (0-9, for png)
image.resizeResize factor (0.1-3)
image.rotateRotation angle (0-360 degrees)
image.roundedBordersAdd rounded borders or border radius (px)
image.paddingPadding (px)
image.smoothUse adaptive filtering
image.cropCrop area
.left (number) - Left offset.top (number) - Top offset.width (number) - Crop width.height (number) - Crop heightvideo.fpsFrames per second
video.recordDurationLimitMax recording duration (seconds)
video.followNewTabFollow new tabs during recording
video.videoFrameVideo frame dimensions
.width (integer) - Frame width.height (integer) - Frame heightvideo.videoCrfConstant Rate Factor (0-51)
video.videoCodecVideo codec
libx264video.videoPresetEncoding preset
ultrafastsuperfastveryfastfasterfastmediumslowslowerveryslowvideo.videoBitrateVideo bitrate (kbps)
headersCustom HTTP headers to send with the request (e.g., cookies, authorization)
asyncEnable async mode for long-running conversions (default: false)
{
"code": 200,
"message": "Render started successfully",
"data": {
"id": "9j0d2plqq49e48l",
"status": "queue"
}
}Check the status of an async render job.
idThe job ID returned from the POST request
{
"code": 200,
"data": {
"id": "11xzi8sjr76hu4z",
"status": "completed",
"createdAt": "2024-09-30T21:08:23.254Z",
"s3_url": "https://..."
}
}id Unique job identifier
status Current job status
queue processing completed failedcreatedAt Job creation timestamp (ISO 8601)
s3_url Signed URL to download the rendered file (when completed)
For long-running conversions, use async mode to avoid timeouts. The API returns immediately with a job ID that you can poll for completion.
# Start async job
curl -X POST https://html2pdfapi.com/api/render \
-H "Content-Type: application/json" \
-d '{
"apiKey": "YOUR_API_KEY",
"url": "https://example.com",
"format": "pdf",
"async": true
}'
# Response: { "data": { "id": "job_abc123", "status": "queue" } }
# Check job status
curl -X POST https://html2pdfapi.com/api/render/job_abc123 \
-H "Content-Type: application/json" \
-d '{"apiKey": "YOUR_API_KEY"}'// Start async job
const startJob = await fetch('https://html2pdfapi.com/api/render', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
apiKey: 'YOUR_API_KEY',
url: 'https://example.com',
format: 'pdf',
async: true
})
});
const { data } = await startJob.json();
const jobId = data.id;
// Poll for completion
const checkStatus = await fetch(
`https://html2pdfapi.com/api/render/${jobId}`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ apiKey: 'YOUR_API_KEY' })
}
);import requests
import time
# Start async job
start_response = requests.post(
'https://html2pdfapi.com/api/render',
json={
'apiKey': 'YOUR_API_KEY',
'url': 'https://example.com',
'format': 'pdf',
'async': True
}
)
job_id = start_response.json()['data']['id']
# Poll for completion
while True:
status = requests.post(
f'https://html2pdfapi.com/api/render/{job_id}',
json={'apiKey': 'YOUR_API_KEY'}
).json()
if status['data']['status'] == 'completed':
print('Done!', status['data']['s3_url'])
break
time.sleep(2)queueprocessingcompletedfailedBusiness and Enterprise plans can configure webhooks to receive notifications when jobs complete.
Generated files are stored on our servers and accessible via signed URLs. Configure storage to match your needs.
Files are stored for 7 days on our servers. Access them via the s3_url in the response.
Configure your own S3 bucket in the dashboard for unlimited retention and full control over your files.
Create an account and get your API key to start converting.