HTML to PDF API
Post an HTML string, get back a PDF and a signed link to download it.
The ASHDOCS HTML to PDF API takes the HTML you already have, renders it on our servers and returns a PDF. Send the markup in one POST request; the response carries a signed download URL that stays valid for an hour. There is nothing to install, no browser to keep patched and no print server to babysit.
It is the same endpoint the dashboard's HTML to PDF tool uses, so a template you test in the browser behaves the same way when you call it from curl, Node, Python or an HTTP step in an automation tool.
curl -X POST https://www.ashdocs.com/api/v1/tools/html-to-pdf \
-H "X-API-Key: ash_test_..." \
-F 'options={"html":"<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>"}'const form = new FormData();
form.append("options", JSON.stringify({
html: "<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>",
}));
const res = await fetch("https://www.ashdocs.com/api/v1/tools/html-to-pdf", {
method: "POST",
headers: { "X-API-Key": "ash_test_..." },
body: form,
});
const job = await res.json();
console.log(job.output_files[0].url);import json
import requests
r = requests.post(
"https://www.ashdocs.com/api/v1/tools/html-to-pdf",
headers={"X-API-Key": "ash_test_..."},
data={"options": json.dumps({"html": "<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>"})},
)
print(r.json()["output_files"][0]["url"])<?php
// HTML to PDF with ASHDOCS: needs PHP's curl extension.
$ch = curl_init("https://www.ashdocs.com/api/v1/tools/html-to-pdf");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"X-API-Key: " . getenv("ASHDOCS_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"html" => "<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>",
]),
CURLOPT_RETURNTRANSFER => true,
]);
$job = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $job["output_files"][0]["url"], PHP_EOL;import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
// HTML to PDF with ASHDOCS: Java 11+ standard library. Run with: java Sample.java
public class Sample {
public static void main(String[] args) throws Exception {
String body = "{\"html\": \"<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>\"}";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://www.ashdocs.com/api/v1/tools/html-to-pdf"))
.header("X-API-Key", System.getenv("ASHDOCS_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
// The job record: output_files[0].url is a signed link to the PDF, valid for one hour.
System.out.println(response.body());
}
}using System.Net.Http.Json;
using System.Text.Json;
// HTML to PDF with ASHDOCS: .NET 6+ standard library.
using var http = new HttpClient();
http.DefaultRequestHeaders.Add("X-API-Key", Environment.GetEnvironmentVariable("ASHDOCS_API_KEY"));
var res = await http.PostAsJsonAsync("https://www.ashdocs.com/api/v1/tools/html-to-pdf",
new { html = "<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>" });
using var job = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
Console.WriteLine(job.RootElement.GetProperty("output_files")[0].GetProperty("url").GetString());require "json"
require "net/http"
# HTML to PDF with ASHDOCS: Ruby standard library.
uri = URI("https://www.ashdocs.com/api/v1/tools/html-to-pdf")
request = Net::HTTP::Post.new(uri, {
"X-API-Key" => ENV.fetch("ASHDOCS_API_KEY"),
"Content-Type" => "application/json",
})
request.body = { html: "<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>" }.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
job = JSON.parse(response.body)
puts job["output_files"][0]["url"]package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
// HTML to PDF with ASHDOCS: Go standard library.
func main() {
body, _ := json.Marshal(map[string]string{
"html": "<h1>Invoice 42</h1><p>Total due: 120.00 USD</p>",
})
req, _ := http.NewRequest("POST", "https://www.ashdocs.com/api/v1/tools/html-to-pdf", bytes.NewReader(body))
req.Header.Set("X-API-Key", os.Getenv("ASHDOCS_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
var job struct {
OutputFiles []struct {
URL string `json:"url"`
} `json:"output_files"`
}
if err := json.NewDecoder(res.Body).Decode(&job); err != nil {
panic(err)
}
fmt.Println(job.OutputFiles[0].URL)
}{
"job_id": "job_8c1f2e7a9b3d",
"request_id": "req_5d0a4c9e1f27",
"tool_key": "html-to-pdf",
"status": "completed",
"output_files": [
{
"filename": "output.pdf",
"size": 8214,
"url": "<signed URL, valid for 1 hour>",
"expires_at": "2026-10-09T13:00:00+00:00"
}
],
"credits_consumed": 0,
"is_test": true
}Response trimmed; values illustrative. Test keys report 0 credits; a live key reports 1. The PHP, Java, C#, Ruby and Go tabs send the same request as JSON and read the key from ASHDOCS_API_KEY.
What the HTML to PDF API renders
Three documents rendered by this endpoint from plain HTML and CSS, page one of each. Paper size, margins and the page counter come from each file's own @page rules.


@page { size: A4 landscape } and a border.
Templates with data
Put {{ variables }} and {% for %} loops in your HTML and send a data object. Values are HTML-escaped, and a missing variable fails the request before any credit is used.
Print CSS that works
@page rules, @font-face, flexbox and page breaks are honored. The page size comes from your CSS; URL→PDF supports A4 and Letter.
Large documents queue
HTML of 2 MB or more is accepted as a background job: you get a 202 with a job ID to poll, and webhooks report completion on paid plans.
How the HTML to PDF API renders your page
Most documents are rendered with WeasyPrint, a CSS layout engine built for paged media. Documents of 512 KB of HTML or more switch to headless Chromium, which is faster on very long files. In both cases JavaScript does not run: WeasyPrint has no script engine, and the Chromium context is created with JavaScript turned off. Build the final markup before you send it.
Because the HTML arrives as a string, there is no page address for relative links to resolve against. Reference images and fonts by absolute https URL or embed them as data URIs. Your CSS controls the paper: set @page { size: A4; margin: 18mm } or size: Letter, and the default is A4 when you set nothing.
Every PDF is checked before the request succeeds: it must be non-empty and structurally valid, and in template mode any leftover {{ }} placeholder fails the job instead of shipping a document with a hole in it.
- Request fields:
html(required),data(template values),strict(default true) andliteral_mode(print braces as-is). - Response: the job record with
output_files[].url, a signed link that expires after one hour. - Cost: 1 credit per PDF on a live key; test keys never use credits.
Convert a URL instead of HTML
When the page already lives on the web, call POST /api/v1/tools/url-to-pdf with a url. That route always uses headless Chromium, waits for the network to go quiet and for web fonts to load, and scrolls the page so lazy-loaded images appear before printing.
URL→PDF accepts format (A4, Letter, Legal, A3 or A5), landscape, margin_mm (0 to 50), scale (0.1 to 2), media (screen or print), viewport, wait_until and wait_extra_ms. Private and cloud-metadata addresses are refused, including when a public URL redirects to one.
From code or from an automation tool
Any HTTP client works: the endpoint takes a multipart or form field named options holding JSON, and the X-API-Key header. From Zapier, Make or n8n, an HTTP step calls the endpoint today. The ASHDOCS Zapier app is public in Zapier's app directory, where it's labeled beta. The ASHDOCS community node installs from npm as n8n-nodes-ashdocs on self-hosted n8n, and n8n's verification of it is still pending. There's no ASHDOCS Make app yet, so in Make you call the API with the HTTP module and your API key.
Add "output": "url" to the options to get a flat body with file_url, expires_at and credits_charged, which is easier to map in a no-code step than the full job record.
How do I try it with a free test key?
Create a free account, copy the test key that starts with ash_test_ from the API keys page and paste it into any of the samples above. Test keys don't expire and never use credits, so you can render as many drafts as you like; your plan's rate limit still applies to them.
- Sign up: the free plan needs no card.
- Copy the
ash_test_key from API keys in the dashboard. - Run one of the samples above with that key, open the URL it prints and check the PDF.
- Switch to a live key when the output looks right; each HTML to PDF render then uses 1 credit.
What happens to my HTML and PDFs? Security and data handling
Your HTML is rendered on ASHDOCS servers and the PDF is stored only long enough for you to fetch it. The download link is a signed URL that expires after one hour, and stored inputs and outputs are deleted after 24 hours by default.
- Signed links: every
output_files[].urlandfile_urlexpires one hour after the render. - Retention: stored files are deleted once they're older than your account's retention setting, 24 hours unless you change it (up to 90 days). With zero retention on, a job's files are deleted within 15 minutes of it finishing.
- No scripts: HTML is rendered with JavaScript off, so code in the markup never runs on our servers.
- URL to PDF refuses private network and cloud-metadata addresses, including when a public URL redirects to one.
- Every request needs your
X-API-Key, and test keys are separate from live keys.
Related reading: HTML to PDF in C#
Related reading: check a PDF against PDF/UA-1
Frequently asked questions
How do I convert HTML to PDF with an API?
Send a POST request to https://www.ashdocs.com/api/v1/tools/html-to-pdf with your API key in the X-API-Key header and a form field named options containing JSON such as {"html": "<h1>Hello</h1>"}. The response includes output_files[0].url, a signed link to the PDF that is valid for one hour. To fill a template, add a data object and use {{ variable }} placeholders in the HTML.
Does it support CSS and web fonts?
Yes. The renderer supports CSS paged media, including @page size and margins, page breaks and @font-face web fonts, along with flexbox and simple grid layouts. Load fonts and images from absolute URLs or data URIs, because HTML sent as a string has no base address for relative paths, and note that JavaScript does not run.
Can I convert a URL instead of HTML?
Yes. POST /api/v1/tools/url-to-pdf takes a url and renders the live page in headless Chromium, with format set to A4, Letter, Legal, A3 or A5. It waits for fonts and lazy-loaded images, and refuses private network addresses.
Is there a free tier?
Yes. The Free plan includes 10 credits per month, each HTML to PDF conversion uses 1 credit, and test keys never use credits. Conversions made with a test key use none, so you can tune your templates for free.
Can it convert JavaScript-heavy pages?
Not from an HTML string: the HTML to PDF renderer runs no JavaScript, so send markup that's already complete. If the page needs scripts to draw charts or load data, publish it and use POST /api/v1/tools/url-to-pdf, which renders in headless Chromium, waits for the network to go quiet by default and can wait up to 10 more seconds with wait_extra_ms.
Does it work from Docker or Linux?
Yes. Nothing runs on your side except an HTTPS request, so any container, Linux server, serverless function or CI job that can make a POST call can use it. There's no browser, font package or native library to install.
How do I convert very large HTML documents?
Send them the same way. HTML of 2 MB or more is accepted as a background job: the response is 202 with a job_id and a status_url, and you either poll for the result or, on paid plans, receive a job.completed webhook.
Can I use it from Zapier or n8n?
Yes. Any HTTP step can call it with your API key, such as Webhooks by Zapier or n8n's HTTP Request node, and adding "output": "url" gives you a file_url to pass to the next step. The ASHDOCS Zapier app is public in Zapier's app directory, where it's labeled beta. The ASHDOCS community node installs from npm as n8n-nodes-ashdocs on self-hosted n8n, and n8n's verification of it is still pending. There's no ASHDOCS Make app yet, so in Make you call the API with the HTTP module and your API key.
Plans
- 10 credits per month
- 1 seat
- No webhooks
- 2,000 credits per month
- 1 seat
- Webhooks
- 10,000 credits per month
- 3 seats
- Webhooks
- 30,000 credits per month
- 5 seats
- Webhooks
- 100,000 credits per month
- 10 seats
- Webhooks
Test keys are free, never expire and never use credits; plan rate limits apply. Webhooks are on paid plans. Issuing an invoice uses 1 credit. No per-seat fees. See full pricing.