Invalid Date

You need to generate invoices, reports, or certificates from your web app — but when you start researching "HTML to PDF conversion," the number of options is overwhelming. wkhtmltopdf, Puppeteer, Gotenberg, cloud APIs… each has trade-offs, and the right choice depends on your use case.

This article is the hub guide for HTML to PDF conversion — covering the full landscape of approaches, how to choose between them, implementation examples, and solutions to common problems. Each topic links to a dedicated deep-dive article so you can quickly find what you need.

The HTML to PDF Conversion Landscape

There are three broad approaches to HTML to PDF conversion.

HTML to PDF Methods
├── 1. Command-line tools (installed on server)
│   ├── wkhtmltopdf (WebKit)
│   └── Chromium / Chrome headless
├── 2. Libraries (embedded in app)
│   ├── Puppeteer / Playwright (Node.js)
│   ├── WeasyPrint (Python)
│   └── dompdf / TCPDF (PHP)
└── 3. Cloud APIs (external service)
    ├── FUNBREW PDF
    ├── PDFShift
    └── Other SaaS services

Comparing the Approaches

1. Command-Line Tools

wkhtmltopdf is a CLI tool built on the WebKit engine. It's lightweight and fast, but support for modern CSS and JavaScript is limited.

Chromium headless runs Chrome/Chromium in headless mode to produce PDFs. It renders exactly like a real browser but consumes significant memory and requires process management on your server.

See wkhtmltopdf vs. Chromium: Detailed Comparison for an in-depth analysis of both tools.

2. Libraries

Puppeteer / Playwright control headless Chromium from Node.js. You get browser-equivalent rendering quality, but you're still responsible for managing the Chromium process on your server.

If you already use Puppeteer and want to migrate to an API for better scalability, see the Puppeteer to PDF API Migration Guide.

WeasyPrint (Python) and dompdf (PHP) require no browser process management, making them easy to get started with — but CSS support is more limited.

3. Cloud APIs

Cloud APIs offload rendering engine management entirely to the provider. Scaling is automatic, and you can start generating PDFs with just an API key. The main trade-off is cost at high volumes and data leaving your infrastructure.

For a detailed comparison of pricing, features, and performance across services, see HTML to PDF API Comparison 2026. For a pricing-focused breakdown, check the PDF API Pricing Comparison.

Decision Matrix

Situation Recommended approach
Already running Chromium on your server Puppeteer / Playwright
Starting fresh, want to ship fast Cloud API
1M+ PDFs per month Cloud API batch or self-hosted
Air-gapped / offline environment Command-line tool
Minimize development resources Cloud API

Getting Started with FUNBREW PDF

FUNBREW PDF provides high-quality Chromium rendering through a simple REST API.

Quick Start (curl)

curl -X POST https://pdf.funbrew.cloud/api/v1/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello, PDF!</h1><p>Generated on 2026-03-31</p>",
    "options": {
      "format": "A4",
      "margin": {
        "top": "20mm",
        "right": "15mm",
        "bottom": "20mm",
        "left": "15mm"
      }
    }
  }' \
  --output hello.pdf

For per-language quickstarts, see the Language-Specific Quickstart Guide. Ruby and Go developers can jump straight to the Ruby & Go Quickstart.

Python

import requests

def html_to_pdf(html: str, api_key: str, options: dict = None) -> bytes:
    response = requests.post(
        "https://pdf.funbrew.cloud/api/v1/generate",
        headers={"Authorization": f"Bearer {api_key}"},
        json={
            "html": html,
            "options": options or {"format": "A4"},
        },
        timeout=120,
    )
    response.raise_for_status()
    return response.content

# Usage
pdf = html_to_pdf(
    html="<h1>Report</h1><p>Content here...</p>",
    api_key="your-api-key",
    options={"format": "A4", "landscape": False},
)
with open("report.pdf", "wb") as f:
    f.write(pdf)

For TypeScript projects, see the TypeScript PDF API Guide for type-safe implementation patterns. To integrate into a Next.js or Nuxt 3 application, see Using PDF API with Next.js and Nuxt 3. Comparing client-side generation (react-pdf, etc.) vs. API generation? See the React PDF Generation Comparison.

Node.js

const axios = require('axios');
const fs = require('fs');

async function htmlToPdf(html, apiKey, options = {}) {
  const response = await axios.post(
    'https://pdf.funbrew.cloud/api/v1/generate',
    { html, options: { format: 'A4', ...options } },
    {
      headers: { Authorization: `Bearer ${apiKey}` },
      responseType: 'arraybuffer',
      timeout: 120000,
    }
  );
  return Buffer.from(response.data);
}

// Usage
htmlToPdf('<h1>Report</h1>', 'your-api-key')
  .then((buf) => fs.writeFileSync('report.pdf', buf))
  .catch(console.error);

PHP

<?php
function htmlToPdf(string $html, string $apiKey, array $options = []): string
{
    $ch = curl_init('https://pdf.funbrew.cloud/api/v1/generate');
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => json_encode([
            'html' => $html,
            'options' => array_merge(['format' => 'A4'], $options),
        ]),
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer {$apiKey}",
            'Content-Type: application/json',
        ],
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 120,
    ]);

    $pdf = curl_exec($ch);
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($statusCode !== 200) {
        throw new \RuntimeException("PDF generation error: HTTP {$statusCode}");
    }
    return $pdf;
}

// Usage
$pdf = htmlToPdf('<h1>Report</h1>', 'your-api-key');
file_put_contents('report.pdf', $pdf);

Framework-Specific Guides

Dedicated implementation guides for popular backend frameworks:

Framework Guide
Java / Spring Boot Java Spring Boot PDF API Guide
PHP / Laravel PHP Laravel PDF API Guide
Python / Django & FastAPI Django & FastAPI PDF API Guide
Next.js / Nuxt 3 Next.js & Nuxt 3 Guide
Ruby / Go Ruby & Go Quickstart
C# / .NET C# ASP.NET Core PDF API Guide

Beyond HTML — Markdown to PDF

If your source content is Markdown rather than HTML, the Markdown to PDF API Guide covers how to convert documentation and knowledge base content into well-formatted PDFs.

Common Problems and Solutions

For an exhaustive list of conversion issues and fixes, see HTML to PDF Troubleshooting: Encoding, Layout & Page Breaks. The most frequent problems are covered below.

Problem 1: Non-Latin Fonts Not Rendering

Cloud APIs typically pre-install common fonts. If characters still appear as boxes, reference Google Fonts via an @import in your HTML. For a systematic approach to CJK font rendering, see the HTML to PDF Japanese Font Guide.

<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap');
  body { font-family: 'Noto Sans JP', sans-serif; }
</style>

Problem 2: Page Breaks in Wrong Places

Use page-break-inside: avoid to prevent mid-block page breaks.

.invoice-item,
.section,
table {
  page-break-inside: avoid;
}

h2, h3 {
  page-break-after: avoid;
}

For an in-depth guide to print CSS and layout control, see the HTML to PDF CSS Optimization Guide. For multi-page table handling, see the HTML to PDF Table Layout Guide. For responsive-to-print conversion tips, see the HTML to PDF Responsive Design Guide.

Problem 3: Background Colors or Images Missing

PDF rendering disables background printing by default. Enable it with:

{
  "options": {
    "printBackground": true
  }
}

Problem 4: Slow Rendering

External resources (images, fonts, stylesheets) are the most common bottleneck.

  • Inline images as Base64
  • Put CSS in <style> tags instead of external files
  • Remove unused JavaScript

Problem 5: Timeout Errors

Complex HTML or large page counts can cause timeouts. Increase your timeout setting or split content into smaller chunks for batch processing. See the PDF API Error Handling Guide for retry strategies.

Use Cases with Dedicated Guides

Invoice Generation

Dynamically generate invoice PDFs from your web application. For template design and variable binding, see the Invoice PDF Automation Guide.

Certificate Generation

Automatically issue completion certificates for training systems and learning platforms. See the Certificate PDF Automation Guide.

Bulk Report Generation

Generate hundreds of PDFs efficiently with the batch API. See the PDF Batch Processing Guide. For implementation patterns that turn dashboard data into automated PDF reports, see the Automated Report PDF Generation Guide. For real-world examples of monthly sales and analytics report automation, see the Report PDF Use Cases page.

Template-Based Generation

Combine Handlebars, Jinja2, or Twig with PDF API for dynamic documents at scale. See the PDF Template Engine Guide.

Asynchronous Generation with Webhooks

Receive a callback when PDF generation is complete instead of polling. See the PDF Webhook Integration Guide.

Third-Party Integrations

PDF API integrates with a variety of tools and platforms:

Infrastructure & DevOps

Dedicated guides for production deployment and CI/CD integration:

Accessibility

For PDFs that must meet legal requirements (ADA, EAA, WCAG), PDF/UA compliance is essential. The PDF Accessibility Guide covers semantic HTML templates, testing tools, and common pitfalls.

PDF Manipulation (Merge, Split, Compress)

Post-generation tasks like merging, splitting, compressing, and watermarking are covered in the PDF Merge, Split & Compress Guide.

Security and Production Readiness

For API key management and handling sensitive data in PDFs, see the PDF API Security Guide. For a full production readiness checklist covering monitoring, scaling, and cost management, see the PDF API Production Checklist.

Core production checklist:

  1. Store API keys in environment variables, never in source code
  2. Use HTTPS only
  3. Implement timeouts and retry logic
  4. Collect error logs and set up monitoring

Try It Now

Paste your HTML into the FUNBREW PDF Playground and convert it instantly — no API key required.

For full API documentation, visit the API Reference. For pricing, see the Pricing Page. For real-world use cases, browse the Use Cases gallery.

Frequently Asked Questions

Q: Can I migrate from wkhtmltopdf without changing my HTML templates?

In most cases yes. Cloud APIs based on Chromium accept standard HTML/CSS, and your existing templates should work with little or no modification. CSS support is actually better than wkhtmltopdf, so you may notice improved rendering. See Puppeteer to PDF API Migration Guide for a detailed migration path.

Q: What's the difference between the quality and fast engines?

The quality engine uses full Chromium rendering — ideal for contracts, invoices, and print-quality documents. The fast engine is 2–3× faster and works well for high-volume batch jobs where precise CSS rendering is less critical. See wkhtmltopdf vs Chromium for engine details.

Q: How do I handle Japanese or CJK fonts?

FUNBREW PDF has Noto CJK fonts pre-installed — no configuration needed. For self-hosted tools on Linux, you need to apt-get install fonts-noto-cjk and rebuild the font cache. See HTML to PDF Japanese Font Guide.

Q: Is it safe to send confidential documents to the API?

Yes. All connections use TLS 1.2+, generated files are automatically deleted after 24 hours, and download URLs have expiry timestamps. IP allowlisting is also available. See PDF API Security Guide.

Summary

Choosing the right HTML to PDF approach:

  • Need something running in minutes: Cloud API is the fastest path
  • Already have Chromium on your server: Puppeteer or Playwright works well
  • Want quality and scalability without infrastructure work: FUNBREW PDF
  • Processing Japanese/CJK text: Cloud API with pre-installed fonts is easiest
  • High volume (100k+ PDFs/month): Batch API with the fast engine

Follow the links in this article to go deeper on any specific topic. If you're unsure which approach fits your needs, the playground lets you test without writing any code first.

Related

Powered by FUNBREW PDF