Open source · Rust · GPL-3.0

HTML + JavaScript → vector PDF, in one small process.

A modern successor to wkhtmltopdf. bdhtml2pdf runs your page's JavaScript, styles it with Firefox's CSS engine and writes a PDF with real, searchable text. No Chromium, no WebKit, no Qt.

$ bdhtml2pdf invoice.html invoice.pdf
A student report rendered by bdhtml2pdf: a gradient header, four KPI cards, a course table, an SVG bar chart of weekly study hours and three columns of Turkish text
Rendered by bdhtml2pdf from one HTML file. The cards, table and chart are built by JavaScript. Open the PDF (36 KB, text selectable).

Pre-release 0.1.0. It works end to end and every number on this page is measured, but it still builds against patched checkouts of fulgur and Blitz until our upstream pull requests are merged. See the known issues.

Features

The modern web, printed

Templates for invoices, reports, certificates and tickets are HTML, and more and more of that HTML is built by JavaScript. bdhtml2pdf renders it as it is.

Modern JavaScript

ES2022+ through the Boa engine. React 18, Vue 3 and Preact apps render, timers included, on a virtual clock that never waits for real time.

Firefox's CSS engine

Stylo, the cascade Firefox ships, not a hand-written subset: nesting, :has(), @layer, grid, flex, multi-column, oklch(), color-mix().

Real PDF

Text stays text, so it can be searched and copied. Fonts are subset. @page, margin boxes, running headers, page counters and repeated table headers work.

Small and fast

One 31 MB binary and one process. About 30–50 MB of memory and 0.07 s for a typical page; a React app with timers takes 0.16 s.

Safe by default

No network access. Files load only from the input's directory. Endless loops, timer floods and memory bombs are stopped by built-in limits.

Images too

PNG and JPEG with --width, --height, --zoom and --quality, like wkhtmltoimage. They come from the same layout as the PDF.

Samples

Rendered by bdhtml2pdf

Every document below was produced by bdhtml2pdf from a single HTML file; the previews show the first page of each PDF. Open a PDF and select its text, or read the HTML source.

First page of the report sample

Report

KPI cards, a table and an SVG chart, all built by JavaScript. Grid layout, color-mix(), three columns of text.

First page of the invoice sample

Invoice

Line items and VAT computed by a script, Turkish lira formatting, and a footer with “Page 1 of 1” from @page margin boxes.

First page of the newsletter sample

Newsletter

Three columns that flow around floated figures, a headline spanning the columns, and columns that continue on page two.

The certificate sample, in landscape

Certificate

Landscape A4 in Turkish, an SVG seal with text on a path, and text-transform under lang="tr": ılgın → Ilgın.

How it works

Maintained Rust libraries, glued together

Every hard part already existed as a maintained Rust library. bdhtml2pdf connects them into one pipeline with one DOM and one style engine, and sends every change it needs upstream as a pull request.

  1. Parsehtml5ever builds the DOM, as browsers do
  2. Run scriptsBoa runs JavaScript against Blitz's DOM; timers drain on a virtual clock
  3. Style and lay outStylo for CSS, Taffy for flex and grid, Parley for text
  4. Paginatefulgur: @page, margin boxes, counters, table and column breaks
  5. WriteKrilla writes the vector PDF; hayro rasterizes it for PNG and JPEG
Components
LibraryRole
BlitzDOM, style and layout glue, and the JavaScript binding
StyloCSS cascade, the engine Firefox uses
Taffy · Parleyblock, flex and grid layout · text shaping and line breaking
BoaJavaScript engine, written in Rust
fulgurpaged media and pagination; ported by us to current Blitz
Krilla · hayroPDF writer · PDF rasterizer for image output

Results

Measured, not claimed

The same pages went through four engines with default settings on one machine (i7-12800H, Fedora 45, median of 5 runs, 19 November 2026). Results are read back from the PDFs; nothing is judged by eye.

Memory for a one-page documentLargest process, MB. Lower is better.
  • bdhtml2pdf31 MB
  • sghtmltopdf10 MB
  • wkhtmltopdf35 MB
  • Chromium250 MB
Install sizeMB on disk. Lower is better.
  • bdhtml2pdf31.5 MB
  • sghtmltopdf13 MB
  • wkhtmltopdf39 MB
  • Chromium432 MB
Correctness and speed
Checkbdhtml2pdf 0.1.0sghtmltopdf 0.8.0wkhtmltopdf 0.12.6Chromium 157
Modern CSS (11)108111
Modern JavaScript (19)180, no JS0, no ES2015+18–19
React, Vue, Preact apps3/30/30/33/3
HTML parsing (7)7767
Turkish (15)128814
Fonts (8)7768
One-page document0.07 s0.02 s0.24 s0.36 s
React app with timers0.16 s——0.38 s
24-page invoice1.07 s0.08 s0.37 s0.71 s

bdhtml2pdf is the only engine besides Chromium that runs modern JavaScript apps and modern CSS, with about an eighth of its memory. It is slower than the JavaScript-free sghtmltopdf on static pages and slower than all of them on very long tables. The install size was 25 MB in the benchmark run and is 31.5 MB since image output was added. Full results and method.

Security

Safe defaults, tested against attacks

HTML-to-PDF services often render documents that users control. The security suite tries to read local files, escape the input directory, reach internal services and exhaust the machine, with every engine on its default settings.

11/11file reads and SSRF blocked
  • No /etc/passwd through iframes, objects, redirects or fetch()
  • No escape from the input directory, including through symlinks
  • No requests to 127.0.0.1 from HTML, CSS, SVG or JavaScript

wkhtmltopdf 9/11 · headless Chromium 1/11

5/5denial-of-service cases stopped
  • while (true) {} ends after a loop limit
  • Timer floods and memory bombs hit bounded limits
  • Billion laughs and 20 000 nested elements finish

wkhtmltopdf 3/5 · headless Chromium 3/5

Threat model, defaults and every case.

Languages

Turkish is a first-class requirement

The whole alphabet is tested in system fonts, web fonts, bold and italic, and it survives text extraction from the PDF. Case mapping follows the language of the text, the kind of detail engines get wrong.

Ç ç Ğ ğ I ı İ i Ö ö Ş ş Ü ü

/* lang="tr" */
text-transform: uppercase;
  istanbul → İSTANBUL
text-transform: capitalize;
  izmir    → İzmir
text-transform: lowercase;
  IŞIK     → ışık

Install

Build it and convert a page

bdhtml2pdf builds from source with Rust 1.92 or newer and the fontconfig development files (fontconfig-devel on Fedora, libfontconfig1-dev on Debian and Ubuntu).

  1. Check out the sources

    Until the upstream pull requests are merged, the build expects patched fulgur and Blitz next to it.

    git clone https://github.com/bahadirdogru/bdhtml2pdf
    git clone -b blitz-master https://github.com/bahadirdogru/fulgur
    git clone -b public-layout-pass https://github.com/bahadirdogru/blitz
  2. Build

    cd bdhtml2pdf
    cargo build --release      # target/release/bdhtml2pdf
  3. Convert

    The options follow wkhtmltopdf. The output extension picks the format: .pdf, .png, .jpg, or .html for the DOM after JavaScript ran.

    bdhtml2pdf --page-size A4 --orientation Landscape \
      --margin-top 15mm report.html report.pdf
    
    # wait until the page sets window.status = "ready"
    bdhtml2pdf --window-status ready --javascript-delay 2000 \
      dashboard.html dashboard.pdf
    
    # a 1280 px wide image of the whole page, at twice the pixels
    bdhtml2pdf --width 1280 --zoom 2 page.html page.png

    All command-line options

Status

Known issues

Found by our own test suites. Details and plans are in the roadmap.

Not there yet

  • Container queries, subgrid and Canvas 2D (SVG charts work)
  • No Intl in JavaScript; Turkish case mapping in CSS works
  • wkhtmltopdf's header and footer flags
  • Ligature letters drop out of extracted text: office → ofce

Next

  • Upstream the Blitz and fulgur changes, then publish releases
  • Faster pagination for long tables
  • A server mode and bindings for Ruby, Python, PHP and Node
  • PDF/A for archiving and Canvas 2D charts