Render HTML or URL to PDF API
Render a public web page or a raw HTML document to a print-quality PDF with headless Chromium — paper size, orientation, margins, scale and page ranges included. Returns base64 PDF bytes.
Part of: HTML to PDF API
How to call it
Send one POST to api.upapi.io/html-to-pdf.post with your key in the X-Api-Key header and the parameters below as a JSON body. Each call spends 20 weighted units of your monthly quota. The operation times out after 25 seconds. Identical requests are served from cache for 300 seconds, unbilled.
POST https://api.upapi.io/html-to-pdf.post
Render HTML or URL to PDF API reference
Request parameters
- url
- string — Absolute http(s) URL to render (e.g. https://example.com). Mutually exclusive with
html. URLs resolving to private, loopback, link-local or cloud-metadata addresses are rejected. - html
- string — Raw HTML document to render, up to 2 MB. Mutually exclusive with
url. Relative asset paths cannot resolve in this mode — use absolute https URLs or inline/data: assets (e.g. <h1>Invoice #42</h1>). - media
- enum — Which CSS media type to emulate. 'screen' (default) reproduces what a visitor sees; 'print' honours the site's print stylesheet (e.g. screen).
- scale
- number — Rendering scale of the webpage, 0.1 to 2 (e.g. 1).
- format
- enum — Paper size (e.g. A4).
- margin
- object — Page margins as CSS lengths. Omitted sides default to zero, matching Chromium (e.g. {"top":"1in","bottom":"1in"}).
- margin.top
- string — Top margin (e.g. 1in).
- margin.left
- object — Left margin (e.g. 0.5in).
- margin.right
- object — Right margin (e.g. 0.5in).
- margin.bottom
- object — Bottom margin (e.g. 1in).
- landscape
- boolean — Print in landscape orientation instead of portrait (e.g. false).
- waitUntil
- enum — When rendering counts as done: 'domcontentloaded' is fastest, 'load' waits for subresources, 'networkidle' waits for the network to go quiet (e.g. load).
- pageRanges
- string — Pages to include. Omit for the whole document (e.g. 1-5, 8).
- printBackground
- boolean — Render background colours and images. Defaults to true — Chromium defaults this off, which strips the visual design most callers are trying to capture (e.g. true).
Response fields
- stringrequired — Base64-encoded PDF bytes. No
data:URI prefix — decode directly. - bytes
- integerrequired — Size of the DECODED PDF in bytes (the base64 string is ~4/3 of this).
- pages
- integer — Page count, read from the PDF itself. Omitted when the structure cannot be read with certainty — the PDF is still valid.
Example request and response
The example response is generated from this operation’s published output schema — it shows the shape and field names, not values from a recorded call.
{
"url": "https://example.com",
"media": "screen",
"scale": 1,
"format": "A4",
"landscape": false,
"waitUntil": "load",
"printBackground": true
}{
"pdf": "example",
"bytes": 1,
"pages": 1
}Code snippets
cURL
curl -X POST https://api.upapi.io/html-to-pdf.post \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{ "url": "https://example.com", "media": "screen", "scale": 1, "format": "A4", "landscape": false, "waitUntil": "load", "printBackground": true }'JavaScript
const response = await fetch('https://api.upapi.io/html-to-pdf.post', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
},
body: JSON.stringify({
"url": "https://example.com",
"media": "screen",
"scale": 1,
"format": "A4",
"landscape": false,
"waitUntil": "load",
"printBackground": true
}),
});
const data = await response.json();
console.log(data);Python
import requests
response = requests.post(
'https://api.upapi.io/html-to-pdf.post',
headers={
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
},
json={
"url": "https://example.com",
"media": "screen",
"scale": 1,
"format": "A4",
"landscape": False,
"waitUntil": "load",
"printBackground": True
},
)
print(response.json())Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{ "url": "https://example.com", "media": "screen", "scale": 1, "format": "A4", "landscape": false, "waitUntil": "load", "printBackground": true }`)
req, _ := http.NewRequest("POST", "https://api.upapi.io/html-to-pdf.post", bytes.NewBuffer(payload))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "YOUR_API_KEY")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var result map[string]any
json.Unmarshal(body, &result)
fmt.Println(result)
}PHP
<?php
$payload = json_encode([
'url' => 'https://example.com',
'media' => 'screen',
'scale' => 1,
'format' => 'A4',
'landscape' => false,
'waitUntil' => 'load',
'printBackground' => true,
]);
$ch = curl_init('https://api.upapi.io/html-to-pdf.post');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'x-api-key: YOUR_API_KEY',
],
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
var_dump($data);Ruby
require 'net/http'
require 'uri'
require 'json'
uri = URI('https://api.upapi.io/html-to-pdf.post')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
request = Net::HTTP::Post.new(uri.path)
request['Content-Type'] = 'application/json'
request['x-api-key'] = 'YOUR_API_KEY'
request.body = { "url": "https://example.com", "media": "screen", "scale": 1, "format": "A4", "landscape": false, "waitUntil": "load", "printBackground": true }.to_json
response = http.request(request)
puts JSON.parse(response.body)Java
import okhttp3.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
OkHttpClient client = new OkHttpClient();
ObjectMapper mapper = new ObjectMapper();
String json = "{ \"url\": \"https://example.com\", \"media\": \"screen\", \"scale\": 1, \"format\": \"A4\", \"landscape\": false, \"waitUntil\": \"load\", \"printBackground\": true }";
RequestBody body = RequestBody.create(json, MediaType.get("application/json"));
Request request = new Request.Builder()
.url("https://api.upapi.io/html-to-pdf.post")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("x-api-key", "YOUR_API_KEY")
.build();
try (Response response = client.newCall(request).execute()) {
Map<?, ?> result = mapper.readValue(response.body().string(), Map.class);
System.out.println(result);
}C#
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");
var payload = JsonSerializer.Deserialize<object>("{ \"url\": \"https://example.com\", \"media\": \"screen\", \"scale\": 1, \"format\": \"A4\", \"landscape\": false, \"waitUntil\": \"load\", \"printBackground\": true }");
var response = await client.PostAsJsonAsync("https://api.upapi.io/html-to-pdf.post", payload);
var result = await response.Content.ReadFromJsonAsync<JsonElement>();
Console.WriteLine(result);Frequently asked questions
How much does the Render HTML or URL to PDF API cost per call?
Each call spends 20 weighted units of your plan's monthly quota. Full pricing is at https://upapi.io/pricing.
How do I authenticate to the Render HTML or URL to PDF API?
Send your key in the X-Api-Key header. A free guest key is available without creating an account.
Are Render HTML or URL to PDF API responses cached?
Yes — identical requests are served from cache for 300 seconds, and a cache hit is not billed.