Convert HTML to PDF with a REST API

Converting HTML to PDF is one of the most common tasks in web development. Whether you need to generate reports, export pages for offline reading, or create printable documents, the process usually involves heavyweight tools like Puppeteer, wkhtmltopdf, or a full headless browser. The Apixies HTML to PDF API removes all of that complexity. Send HTML in, get a PDF back -- no infrastructure to manage, no browser binaries to install.

Why use a REST API instead of a local tool?

Running Puppeteer or wkhtmltopdf on your own server sounds straightforward until you actually do it. Here is what you are signing up for:

  • Headless browser installation -- Chromium alone weighs hundreds of megabytes and requires specific OS-level dependencies (libX11, libatk, fonts, etc.).
  • Memory pressure -- Each render spawns a browser process. Under load, your server's RAM can spike unpredictably.
  • Version management -- Chromium updates frequently, and breaking changes can silently alter your PDF output.
  • Containerization headaches -- Getting headless Chrome to work reliably inside Docker adds another layer of configuration, especially on Alpine-based images.
  • Scaling -- If you need to generate 500 PDFs an hour, you either over-provision your server or build a dedicated worker queue.

A REST API sidesteps all of this. You make an HTTP POST request with your HTML and receive a binary PDF in the response. The rendering, scaling, and browser management happen on the API provider's infrastructure.

Self-hosted vs. API: a quick comparison

Concern Self-Hosted (Puppeteer, wkhtmltopdf) Apixies REST API
Setup time Hours to days (dependencies, Docker config, testing) Minutes (one HTTP call)
Server resources High -- each render needs CPU and RAM None -- rendering happens remotely
Maintenance Ongoing browser updates, dependency patches Zero -- always up-to-date
Scaling Manual -- worker queues, load balancers Automatic -- handled by the API
Cost at low volume Server costs even for a few PDFs/day Free -- 75 requests/day included

For teams that generate fewer than a few thousand PDFs per day, a hosted API is almost always the more practical choice.

How the Apixies HTML to PDF endpoint works

The endpoint is simple by design:

Detail Value
URL POST https://apixies.io/api/v1/html-to-pdf
Auth X-API-Key header
Input html parameter in the POST body
Output Binary PDF file (application/pdf)

You send an HTML string, and the API returns a fully rendered PDF. The HTML can include inline CSS, Google Fonts, images via absolute URLs, tables, flexbox layouts -- anything a modern browser can render.

Step-by-step: your first HTML to PDF conversion

Step 1 -- Get a free API key

Register for a free account at apixies.io. You will receive an API key immediately. The free tier gives you 75 requests per day with a registered account (or 20 per day for anonymous requests without a key), which is plenty for development, testing, and low-volume production use.

Step 2 -- Prepare your HTML

Your HTML string should be a complete, self-contained document. Inline your CSS or reference external stylesheets via absolute URLs. Here is a minimal example:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body { font-family: Helvetica, Arial, sans-serif; padding: 40px; }
        h1 { color: #1a202c; border-bottom: 2px solid #319795; padding-bottom: 10px; }
        p { line-height: 1.6; color: #4a5568; }
    </style>
</head>
<body>
    <h1>Monthly Report</h1>
    <p>This PDF was generated from HTML via the Apixies API.</p>
    <p>Generated on: 2026-02-20</p>
</body>
</html>

Step 3 -- Make the API call

Use any HTTP client. Here is a quick example with cURL:

curl -X POST https://apixies.io/api/v1/html-to-pdf \
  -H "X-API-Key: YOUR_API_KEY" \
  -d 'html=<!DOCTYPE html><html><head><style>body{font-family:sans-serif;padding:40px}h1{color:%231a202c}</style></head><body><h1>Hello PDF</h1><p>Generated via REST API.</p></body></html>' \
  --output report.pdf

The --output report.pdf flag saves the binary response directly to a file. Open report.pdf in any PDF reader to verify the result.

Step 4 -- Integrate into your application

In a real application, you would build the HTML string dynamically (using a template engine, string concatenation, or a dedicated view) and then POST it to the API. Here is a concise Node.js example:

const fs = require('fs');

const html = `
<!DOCTYPE html>
<html>
<head><style>body { font-family: sans-serif; padding: 40px; }</style></head>
<body>
  <h1>Order Confirmation</h1>
  <p>Thank you for your purchase, order #10042.</p>
</body>
</html>`;

const res = await fetch('https://apixies.io/api/v1/html-to-pdf', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: new URLSearchParams({ html }),
});

const buffer = Buffer.from(await res.arrayBuffer());
fs.writeFileSync('confirmation.pdf', buffer);
console.log('PDF saved as confirmation.pdf');

For more language-specific examples, see the code examples guide which covers cURL, JavaScript, PHP, and Python.

Tips for reliable PDF output

Use absolute URLs for assets. Relative paths like ./logo.png will not resolve. Use fully qualified URLs such as https://yourdomain.com/images/logo.png.

Inline critical CSS. While external stylesheets work, inlining CSS in a <style> tag guarantees it loads instantly and avoids network-dependent rendering delays.

Set explicit page dimensions with CSS. Use @page rules to control paper size and margins:

<style>
  @page { size: A4; margin: 20mm; }
  body { margin: 0; }
</style>

Test with simple HTML first. Start with a basic document to confirm connectivity, then layer in complexity. This isolates rendering issues from API integration issues.

Handle errors gracefully. If the API returns a non-200 status code, the response body will be JSON with an error message rather than a PDF. Always check the Content-Type header or HTTP status before writing the response to a file.

What you can build with this

The HTML to PDF API is useful anywhere you need to turn structured content into a downloadable or printable document:

  • Invoices and receipts -- Generate billing documents from your database. See the invoice generation guide for a detailed walkthrough.
  • Reports and dashboards -- Export weekly metrics, analytics summaries, or project status reports.
  • Contracts and agreements -- Render legal documents with dynamic fields filled from your application.
  • Certificates -- Create course completion certificates, event tickets, or award letters.
  • Email attachments -- Generate a PDF on the fly and attach it to a transactional email.

Free tier and pricing

Apixies offers a generous free tier so you can develop and test without entering payment details. Registered accounts get 75 requests per day at no cost. Anonymous requests (no API key) are limited to 20 per day. For higher volumes, paid plans are available -- but the free tier is more than enough to build a working integration and validate the output before committing.

Next steps

Ready to start generating PDFs? Get your free API key and follow the full API documentation for parameter details and advanced options. You can also explore all available endpoints and tutorials on the guides page.

Try the HTML to PDF Converter API

Free tier is for development & small projects. 75 requests/day with a registered account.

Getting Started

Explore

Resources

Get Started Free

Free for development and small projects.

Get Free API Key