An HTML to PDF converter for documents such as invoices, reports and certificates, written in Rust with no browser dependency. It aims to be a replacement for wkhtmltopdf, which is no longer maintained, and accepts the same command line.
Status: early development. presswork renders text documents styled and images with a useful subset of CSS. Floats, positioning, flexbox and grid are not supported yet.
- HTML to PDF, end to end. HTML5 parsing; paragraphs, headings, lists with hanging markers, preformatted text and tables.
- CSS.
<style>elements,<link rel=stylesheet>,@import,style=""attributes and a built-in default stylesheet, with the full cascade (specificity, source order,!important, inheritance) and Selectors Level 4 matching (:nth-child,:not,:is, attribute selectors, combinators,::beforeand::after).@media printrules apply;@media screenrules do not. Supported properties:- text:
color,font-family,font-size,font-weight,font-style,font,line-height,text-align,white-space,text-indent,text-transform,letter-spacing,word-spacing,vertical-align(<sup>,<sub>and the keyword values) - text decoration:
text-decoration(underline, overline and line-through, drawn solid),text-decoration-line,text-decoration-color - boxes:
display,margin,padding,border(solid, dashed, dotted and double; other styles are drawn solid),border-radius,width,max-width,height,min-height,max-height,box-sizing,overflow(clips content and contains floats) - floats and positioning:
float,clear,position(relative,absolute, andfixed, which repeats on every page, for watermarks),top,right,bottom,left,inset - backgrounds:
background-color,background-image(PNG, JPEG, GIF, WebP andlinear-gradient()),background-repeat,background-position,background-size(cover,contain, lengths) and thebackgroundshorthand. A background on<html>or<body>covers every page - inline elements: backgrounds,
border,paddingand horizontalmarginon<span>,<a>,<strong>and the like, drawn on each line the element covers;display: inline-blockboxes, sized to their content or theirwidthand aligned by their last line - images:
width,height,max-width,max-height,vertical-align - tables:
border-collapse,border-spacing,table-layout,vertical-align,heighton cells and rows - lists:
list-style-type, includingdevanagari - generated content:
content(strings,counter(),counters(),attr(), quotes) on::beforeand::after,counter-reset,counter-increment,counter-set - pages:
break-before,break-after,break-inside(pageandavoid) and thepage-break-*aliases,orphans,widows - fonts:
@font-facewith TrueType, OpenType and WOFF files, loaded only when text uses them
- text:
- Legacy HTML attributes that wkhtmltopdf-era templates rely on:
align,valign,width,height,bgcolor,background,border,cellpadding,cellspacing,nowrapand<font>. - Images. PNG, JPEG, GIF and WebP in
<img>, inline or as blocks, sized by their attributes and CSS and scaled to fit withmax-width. An image that fails to load is reported and replaced by itsalttext. - Linked files. Images, stylesheets and fonts given as
data:URLs always load. Local files load only with--enable-local-file-accessor from a directory given with--allow, as in wkhtmltopdf 0.12.6. Relative URLs resolve against the input file (or the current directory for standard input), and inside a stylesheet against the stylesheet. - Tables. Columns are sized to their content and to the widths given
to cells and
<col>s (columns with a width keep it; the others share the rest), withcolspanandrowspan, cell borders and backgrounds, and collapsed borders, where the borders of cells, rows, row groups, columns and the table meet and the strongest wins, as in browsers. Rows are never split across pages, nor are rows joined by arowspancell;<thead>rows repeat at the top of every page, and a header is never left alone at the bottom of a page. - Pagination. Pages break between lines and table rows; backgrounds and
borders continue across the break.
@page { size; margin }is honored. A box withbreak-inside: avoidmoves to the next page whole when it fits there, headings stay with the content that follows them, and paragraphs leave at least two lines on each page. - Text in any script the system has fonts for. Text is shaped with HarfBuzz-compatible shaping, so Devanagari conjuncts and vowel signs render correctly, and fonts fall back by script. Symbols (✔, ★, →) and emoji that the text's fonts lack come from installed symbol and emoji fonts, such as Noto Sans Symbols 2 and Noto Color Emoji. Fonts are embedded and subsetted, and the PDF text can be searched and copied.
- Document metadata. The
<title>becomes the PDF title unless--titleis given. - Bookmarks and links. Headings (
<h1>to<h6>) become the PDF outline, nested by level.<a href>links are clickable: links to other documents open them, and links to anidor<a name>in the document jump to it. - wkhtmltopdf's command line. Every documented wkhtmltopdf 0.12.6 option
is recognised, so invocations from wrapper libraries such as
pdfkit,wicked_pdfandsnappyparse:-reads HTML from standard input or writes the PDF to standard output.file://input URLs are accepted.-Vreportswkhtmltopdf 0.12.6 (presswork <version>), so wrappers that check the version (such aswicked_pdf) use the current argument style.- Options that are not implemented yet are ignored with a warning. Options unknown to wkhtmltopdf are rejected, as wkhtmltopdf does.
-q/--quietand--log-level nonesilence warnings, except for ignored options that change the output, such as HTML headers and zoom. Those are always reported, becausepdfkitpasses--quietby default.--strict, orPRESSWORK_STRICT=1in the environment, makes those options an error instead of a warning. Use the environment variable when a wrapper library builds the command line for you.
- Page options.
-s/--page-sizeaccepts every size wkhtmltopdf does (A0–A9, B0–B10, C5E, Comm10E, DLE, Executive, Folio, Ledger, Legal, Letter, Tabloid).-O/--orientation,--page-width,--page-height,-T/-R/-B/-L(--margin-*) and--titleare supported. Options given on the command line win over the document's@pagerule. - Resource options.
--enable-local-file-access,--disable-local-file-access,--allow,--images,--no-images,--load-media-error-handling(abortstops without writing the PDF) and--user-style-sheet, which the document's own styles override unless it uses!important. The user stylesheet is read whatever the file access options say, since whoever runs presswork named it. - Text headers and footers.
--header-left,--header-center,--header-right, the--footer-*equivalents,--header-font-name,--header-font-size,--header-line,--header-spacing(and their footer versions),--default-header,--page-offsetand--replace. Placement matches wkhtmltopdf: the text sits in the page margin just outside the content, so give it room with--margin-topor--margin-bottom. These variables are replaced:[page],[topage],[frompage],[sitepage],[sitepages],[title],[doctitle],[webpage],[date],[isodate],[time], and[section],[subsection]and[subsubsection](the headings in effect on the page), plus any set with--replace. The text can be in any script, for example--footer-center "पृष्ठ [page] / [topage]". - Outline and link options.
--outline,--no-outline,--outline-depth(default 4),--enable-external-links,--disable-external-links,--enable-internal-linksand--disable-internal-links. - HTML headers and footers.
--header-htmland--footer-htmltake a path orfile:URL and draw that document in the top or bottom margin of every page. Without--margin-top(or--margin-bottom), the margin grows to fit it; with one, the margin grows by the spacing, as in wkhtmltopdf. Images and stylesheets it links to follow the file access options. Page numbers work through the usual wkhtmltopdf script without running it; see below.
Not yet: SVG images, radial gradients, WOFF2 fonts and unicode-range,
flexbox and grid, z-index, and the table of contents.
presswork [OPTIONS] <INPUT> <OUTPUT>
presswork --page-size Letter --margin-top 20mm invoice.html invoice.pdf
cat invoice.html | presswork --quiet - - > invoice.pdf- No JavaScript.
--javascript-delay,--window-statusand--run-scripthave no effect. Render dynamic content on the server first. HTML headers and footers usually carry the script from wkhtmltopdf's documentation, which fills elements with classpage,topage,titleand so on from the URL. When a header or footer has a script, presswork fills those elements itself, with every variable a text header can use, so such templates work unchanged. Other scripts do not run; presswork warns when a header's script has nothing it can fill. - HTML header placement. The header's
<body>box ends right above the content (less--header-spacing), and a footer's starts right below it, so a body margin stays outside the page margin instead of pushing the header into the content or the footer off the page. - No network access. Documents and images are never fetched from
http(s)://URLs. An image that would need the network is reported even under--quiet, since wkhtmltopdf would have loaded it, and--strictmakes it an error. Embed such images asdata:URLs or local files. - Standards-based layout. Output follows the CSS specifications, not QtWebKit, so templates tuned for wkhtmltopdf's rendering (for example its smart shrinking) may lay out differently.
- Boxes grow to fit. Content taller than a box's
heightmakes the box taller instead of overflowing it, so text never runs into what follows.overflow: hiddenclips content that is too wide, but not content that is too tall, since the box grows to hold it. - Page breaks. wkhtmltopdf ignores
orphansandwidowsand can cut a line of text in half at a page break. presswork never splits a line, keeps at least two lines of a paragraph on each page (the CSS default), and keeps headings with what follows them, as print formatters do, so pages may break a little earlier than in wkhtmltopdf. - Print media. Stylesheets are evaluated for
printmedia, so@media screenrules do not apply. wkhtmltopdf usesscreenunless--print-media-typeis given. - System fonts. Fonts come from the system's font configuration, so
output can differ between machines with different fonts installed. Use
@font-faceto make a document look the same everywhere. On Linux, fontconfig is loaded at runtime: building needs no fontconfig development package, but rendering text needs fontconfig and fonts installed (presswork warns if it finds none). - One input document. Multiple inputs, cover pages and
tocobjects are not supported yet. - Header dates.
[date]and[time]always use wkhtmltopdf's format for the C locale (17 Nov 2026,20:06:55), the usual one on servers. wkhtmltopdf followsLANG, so it may write11/17/26instead.
Requires Rust 1.92 or newer.
cargo build --release
cargo test --workspaceLicensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.