Skip to main content

The problem

PDF rendering depends on external assets: fonts, images, stylesheets. Any of these can fail, be slow, or load in the wrong order — causing blank areas, wrong fonts, or broken layouts. PDFBase gives you explicit control over asset loading behavior.

wait_until

Controls when PDFBase considers the page “ready” to capture: Default: networkidle (safest, slightly slower).

wait_for_selector

Wait for a specific CSS selector to appear before capturing. Useful when JavaScript dynamically creates content:
In your app, set a flag when content is ready:

wait_for_timeout

Add a fixed delay after wait_until fires. Use as a last resort when there’s no reliable signal:
Fixed delays are fragile. Prefer wait_for_selector when possible — it’s both faster (no unnecessary waiting) and more reliable (doesn’t break if load time varies).

resource_timeout

Max time to wait for each individual resource. Resources that exceed this are skipped:
Default: 10,000ms (10 seconds).

skip_failed_resources

Controls behavior when a resource fails to load:
  • true (default): Continue rendering. The PDF will have missing images or fallback fonts, but it will generate.
  • false: Fail the entire request. Returns an error listing the failed resources.
Use false for templates where every asset is critical (e.g., a branded certificate where the logo must be present).

Font loading

Google Fonts

Just link them in your HTML. They load automatically:

Bundled fonts

PDFBase includes 6 high-quality font families that don’t require any network loading:
  • Inter — Clean sans-serif (body text)
  • JetBrains Mono — Monospace (code)
  • Merriweather — Serif (documents)
  • Noto Sans — Wide Unicode coverage (internationalization)
  • Noto Sans CJK — Chinese, Japanese, Korean
  • Noto Sans Arabic — Arabic script
Use these for fastest rendering and no font-loading risk.

Fallback behavior

When a custom font fails to load (network error, timeout, 404), PDFBase automatically falls back to the closest bundled font based on the CSS font-family stack: The fallback is CSS-standard: PDFBase follows your font-family stack, substituting the first available bundled font that matches the generic family. If no generic family is specified, Inter is the final fallback. To see which font was actually used, enable debug: true. The console output will log any font substitution:
Always include a generic family (sans-serif, serif, monospace) at the end of your font-family stack. This ensures predictable fallback behavior and matches how browsers handle missing fonts.

Custom fonts

Host your font files on a CDN and use @font-face:
Use .woff2 format for smallest file size and fastest loading. Avoid .ttf — it’s 2-3x larger.

Image loading

Inline images (base64)

For critical images that must always appear, embed them as base64:
Trade-off: larger HTML payload, but zero network risk.

Remote images

For non-critical images, use URLs. Pair with resource_timeout and skip_failed_resources: