April 21, 2026

Migrating from wkhtmltopdf: @page CSS, Fonts & API Guide

wkhtmltopdfmigrationPDF generationCSStutorial

You've been using wkhtmltopdf to generate PDFs. Now @page { size: A4; margin: 0; } isn't working as expected, Japanese text shows as tofu boxes, or your CSS Grid layout is completely broken.

wkhtmltopdf converts HTML to PDF with Qt WebKit, and Qt WebKit itself was deprecated in 2015 and removed from Qt in 2016. The wkhtmltopdf GitHub repository is now archived.

This guide covers what's different between wkhtmltopdf and Chromium-based PDF engines, and shows you how to migrate to FUNBREW PDF with working code in curl, Python, and Node.js.

wkhtmltopdf's Current Status

End of Active Maintenance

wkhtmltopdf's latest release is 0.12.6, released in June 2020. The GitHub repository is archived (read-only), and no release has followed. The official status page says:

  • "QtWebKit was eventually deprecated in 2015 and removed in 2016."
  • "Do not use wkhtmltopdf with any untrusted HTML – be sure to sanitize any user-supplied HTML/JS"

Why This Matters for Production

Risk Impact
Repository archived Do not expect fixed releases for bugs or vulnerabilities
Untrusted HTML The project itself warns you to sanitize user-supplied HTML/JS
Old rendering engine Pages built with newer CSS can break when converted
OS-level font dependency Server migrations without the fonts break Japanese rendering

CSS Compatibility: wkhtmltopdf vs Chromium

Here's what to know about the differences before you migrate.

@page Rule Behavior

Common @page declarations:

@page {
  size: A4;
  margin: 0;
}

/* Different margin on the first page */
@page :first {
  margin-top: 60mm;
}

/* Page numbers (margin boxes; Chromium supports them from Chrome 131) */
@page {
  @bottom-center {
    content: counter(page) " / " counter(pages);
  }
}

With wkhtmltopdf, paper size and margins are normally set with CLI options. The left and right margins default to 10mm, so pass the margins explicitly when you want zero:

# wkhtmltopdf: margins via CLI options
wkhtmltopdf \
  --margin-top 0 \
  --margin-right 0 \
  --margin-bottom 0 \
  --margin-left 0 \
  --page-size A4 \
  input.html output.pdf

The FUNBREW PDF API also takes paper size and margins from the request options. The quality engine (Chromium) uses the options.page-size paper size rather than CSS @page size, and sends margins from margin-top, margin-right, margin-bottom and margin-left (mm, 0 to 50, 10 when omitted):

{
  "options": {
    "page-size": "A4",
    "margin-top": 0,
    "margin-right": 0,
    "margin-bottom": 0,
    "margin-left": 0
  }
}

If you keep @page { margin: ... } in your CSS, use the same values as options and check the margins in the output PDF.

Feature Support Comparison

CSS Feature wkhtmltopdf Chromium (FUNBREW PDF quality engine)
Paper size and margins CLI options (--page-size, --margin-*) API options (page-size, margin-*)
@page margin boxes (headers/footers) Use --header-html, --footer-html and similar options instead Supported from Chrome 131
Newer CSS such as Grid, Flexbox, custom properties Depends on Qt WebKit; verify the output Follows Chromium's implementation
Japanese fonts Must be installed on the OS Expected to use Noto Sans CJK JP (verify the output)

FUNBREW PDF's fast engine is wkhtmltopdf. To render with Chromium, set "engine": "quality" (Pro plan or above; on Free, quality returns 403, and omitting engine renders with fast).

Page Break Control

/* Declaring both the new and old properties works well across engines */
.keep-together {
  break-inside: avoid;          /* modern standard */
  page-break-inside: avoid;     /* fallback for compatibility */
}

Migration Code: wkhtmltopdf to FUNBREW PDF API

Step 1: Map CLI Options to API options

Map your wkhtmltopdf CLI options to the API options:

wkhtmltopdf FUNBREW PDF API options
--page-size A4 "page-size": "A4" (A3, A4, A5, Letter, Legal)
--orientation Landscape "orientation": "Landscape"
--margin-top 10mm etc. "margin-top": 10 etc. (number in mm, 0 to 50)
--header-html, --footer-html No equivalent option (use CSS margin boxes, or add page numbers after generation with /api/pdf/page-numbers)

Keys not in this table, such as format, are silently ignored rather than rejected, so use the names above. There is no option for --encoding; put <meta charset="UTF-8"> in your HTML.

Step 2: Replace the subprocess call

The API returns JSON, and the PDF itself is fetched from data.download_url with the same API key.

curl:

# Before: wkhtmltopdf CLI
# wkhtmltopdf --page-size A4 input.html output.pdf

# After: FUNBREW PDF API
curl -X POST https://pdf.funbrew.cloud/api/pdf/generate-from-html \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<html>...</html>",
    "options": {
      "engine": "quality",
      "page-size": "A4",
      "margin-top": 10,
      "margin-bottom": 10,
      "margin-left": 15,
      "margin-right": 15
    }
  }'
# GET data.download_url from the response with the same API key to save the PDF

To read from a file, send it, and save the PDF (uses jq):

API_KEY="sk-your-api-key"

BODY=$(jq -n --rawfile html input.html \
  '{html: $html, options: {engine: "quality", "page-size": "A4", "margin-top": 10, "margin-bottom": 10, "margin-left": 15, "margin-right": 15}}')

DOWNLOAD_URL=$(curl -sf -X POST https://pdf.funbrew.cloud/api/pdf/generate-from-html \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d "$BODY" | jq -r '.data.download_url')

curl -sf -H "Authorization: Bearer $API_KEY" -o output.pdf "$DOWNLOAD_URL"

Python:

import requests

API_KEY = 'sk-your-api-key'
HEADERS = {'Authorization': f'Bearer {API_KEY}'}

# Before: wkhtmltopdf via subprocess
# import subprocess
# subprocess.run([
#     'wkhtmltopdf',
#     '--page-size', 'A4',
#     '--margin-top', '10mm',
#     '--encoding', 'utf-8',
#     'input.html', 'output.pdf'
# ])

# After: FUNBREW PDF API
with open('input.html', 'r', encoding='utf-8') as f:
    html_content = f.read()

response = requests.post(
    'https://pdf.funbrew.cloud/api/pdf/generate-from-html',
    headers=HEADERS,
    json={
        'html': html_content,
        'options': {
            'engine': 'quality',
            'page-size': 'A4',
            'margin-top': 10,
        },
    },
)
response.raise_for_status()
data = response.json()

# Download the generated PDF (the same API key is required)
pdf_response = requests.get(data['data']['download_url'], headers=HEADERS)
pdf_response.raise_for_status()
with open('output.pdf', 'wb') as f:
    f.write(pdf_response.content)

print('PDF generated:', data['data']['filename'])

Node.js (18 or later; save as .mjs):

import fs from 'node:fs';

// Before: wkhtmltopdf via child_process
// import { execSync } from 'node:child_process';
// execSync('wkhtmltopdf --page-size A4 input.html output.pdf');

// After: FUNBREW PDF API
const API_KEY = 'sk-your-api-key';
const htmlContent = fs.readFileSync('./input.html', 'utf-8');

const response = await fetch('https://pdf.funbrew.cloud/api/pdf/generate-from-html', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    html: htmlContent,
    options: {
      engine: 'quality',
      'page-size': 'A4',
    },
  }),
});
if (!response.ok) throw new Error(`Generation failed: ${response.status}`);

const result = await response.json();

// Download the generated PDF (the same API key is required)
const pdfResponse = await fetch(result.data.download_url, {
  headers: { 'Authorization': `Bearer ${API_KEY}` },
});
if (!pdfResponse.ok) throw new Error(`Download failed: ${pdfResponse.status}`);
fs.writeFileSync('./output.pdf', Buffer.from(await pdfResponse.arrayBuffer()));

console.log('PDF generated:', result.data.filename);

Japanese Font Migration

The wkhtmltopdf Font Problem

With wkhtmltopdf, rendering Japanese text required font installation on every Linux server:

# Debian/Ubuntu
sudo apt-get install -y fonts-noto-cjk

# Or embed the font with @font-face and Base64

If the fonts weren't installed — or if a server was provisioned without them — Japanese text silently broke.

Japanese Fonts in FUNBREW PDF

The FUNBREW PDF quality engine is expected to use the Noto Sans CJK JP font. Set font-family in your CSS and check that Japanese renders correctly in the output PDF:

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <style>
    body {
      font-family: 'Noto Sans CJK JP', sans-serif;
      font-size: 14px;
      line-height: 1.7;
    }
    h1 { font-weight: 700; }
  </style>
</head>
<body>
  <h1>日本語タイトル</h1>
  <p>ひらがな、カタカナ、漢字、記号(①②③)の表示を出力PDFで確認します。</p>
</body>
</html>

To pin a specific font, or for Base64 font embedding, see the Japanese font guide.

Common Post-Migration Issues

Issue 1: Margins Changed

Cause: The margins you set with wkhtmltopdf CLI options were not moved to the API options (when omitted, all four margins are 10mm).

Fix: Set margin-top, margin-right, margin-bottom and margin-left in options as numbers in mm. If your CSS @page also sets margins, use the same values. Use the Playground to check the output:

{
  "options": {
    "page-size": "A4",
    "margin-top": 15,
    "margin-bottom": 15,
    "margin-left": 20,
    "margin-right": 20
  }
}

Issue 2: Page Break Positions Changed

Cause: The rendering engine changes, so the same CSS can break pages in different places.

Fix: Explicitly declare break behavior for all elements that should stay together:

.invoice-footer,
.data-card,
.section-header {
  break-inside: avoid;
  page-break-inside: avoid; /* fallback */
}

.new-chapter {
  break-before: page;
}

See the CSS tips guide for the full page break reference.

Issue 3: Headers/Footers Behavior Changed

Cause: wkhtmltopdf had --header-html and --footer-html CLI options. The API has no equivalent options.

Fix (CSS approach): Use @page margin boxes (Chromium supports them from Chrome 131; check the output):

@page {
  @bottom-center {
    content: "Page " counter(page) " of " counter(pages);
    font-size: 9pt;
    color: #6b7280;
  }

  @top-right {
    content: "Confidential";
    font-size: 8pt;
    color: #9ca3af;
  }
}

Leave room for them with the API margins, for example "margin-bottom": 25.

Fix (API approach): To add page numbers only, send the filename of the generated PDF to /api/pdf/page-numbers. See the API docs for details.

Issue 4: Slightly Different Visual Output

Cause: The rendering engine changes from Qt WebKit to Chromium, so CSS workarounds you added for wkhtmltopdf can produce different results.

Fix: Paste your HTML into the Playground, generate a PDF and adjust while checking the output (the Playground renders with the quality engine and adds a TEST watermark). Remove any wkhtmltopdf-specific CSS workarounds you no longer need.

Migration Checklist

Use this checklist to track your migration:

□ Obtain FUNBREW PDF API key (the quality engine needs Pro plan or above)
□ Move CLI page size and margin flags to API options (page-size, margin-*)
□ Verify HTML encoding is UTF-8 (<meta charset="UTF-8">)
□ Add a font-family for Japanese text
□ Declare page breaks with break-inside / break-before (keep page-break-* as fallback)
□ Test with representative HTML in the Playground
□ Run integration test with production HTML
□ Visually verify: page count, margins, fonts, page breaks
□ Remove wkhtmltopdf subprocess calls from codebase

Summary

Aspect wkhtmltopdf FUNBREW PDF (quality engine)
Rendering engine Qt WebKit Chromium
Paper size and margins CLI options API options
Japanese fonts Manual OS install required Expected to use Noto Sans CJK JP (verify the output)
Project status GitHub repository archived —
Headers/footers CLI --header-html, --footer-html CSS @page margin boxes (Chrome 131+) or the page-number API
JavaScript Enabled by default Runs, but the page prints as soon as it loads

For basic HTML-to-PDF conversion, the core of the migration is: replace the subprocess call with an API request and move the CLI options to options. Because the engine changes, compare the output with your production HTML before you switch.

Try your HTML in the Playground to verify the output before updating production code. Full API details are in the API reference.

Related

Powered by FUNBREW PDF