Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

wkhtmltopdf option mapping

This covers every option listed by --extended-help in wkhtmltopdf 0.12.6, that is the official manual at https://wkhtmltopdf.org/usage/wkhtmltopdf.txt. The sections and their order follow that manual.

SymbolMeaning
✅ SupportedAvailable under the same name with the same meaning as in wkhtmltopdf
❌ Not supportedDeliberately not implemented. Passing one prints what to use instead and exits with code 1; it is never ignored silently

The behavioural differences people trip over when moving across are collected in Migrating from wkhtmltopdf.

Differences in the command line itself

wkhtmltopdf specifies the cover and the table of contents as positional arguments.

wkhtmltopdf cover cover.html toc page.html out.pdf          # wkhtmltopdf
sghtmltopdf --cover cover.html --toc page.html -o out.pdf   # sghtmltopdf

sghtmltopdf takes a single HTML file as input and uses the --cover <path> and --toc options instead. Merging several HTML files, which wkhtmltopdf does by listing them as positional arguments, is not supported.

For the same reason --exclude-from-outline and --include-in-outline, which exclude individual input pages from the outline, are out of scope.

Global Options

OptionRationaleNotes
--collate, --no-collate❌ Not supportedCollation when printing; it means nothing when producing a PDF
--cookie-jar <path>❌ Not supportedAuthenticated fetching is out of scope
--copies <number>❌ Not supportedAs above; it is a printing concern
-d, --dpi <dpi>✅ Supported96 by default
-H, --extended-help❌ Not supportedFolded into --help
-g, --grayscale✅ Supported
-h, --help✅ SupportedGenerated by clap
--htmldoc, --manpage, --readme, --license❌ Not supportedThe documentation lives in docs/ and the README
--image-dpi <integer>❌ Not supportedImages are never resampled
--image-quality <integer>❌ Not supportedThere is no JPEG decoder or encoder; the data is embedded as it is
--log-level <level>✅ Supportednone, error, warn, info
-l, --lowquality❌ Not supportedThere is no counterpart to WebKit’s rasterisation quality setting
-B, --margin-bottom <unitreal>✅ Supported
-L, --margin-left <unitreal>✅ SupportedThe default differs; see below
-R, --margin-right <unitreal>✅ SupportedThe default differs; see below
-T, --margin-top <unitreal>✅ Supported
-O, --orientation <orientation>✅ SupportedPortrait, Landscape
--page-height <unitreal>✅ Supported
-s, --page-size <Size>✅ SupportedA4, A3, A5, Letter, Legal
--page-width <unitreal>✅ Supported
--no-pdf-compression✅ SupportedFlate compression is currently always on
-q, --quiet✅ SupportedThe same as --log-level none
--read-args-from-stdin❌ Not supportedStandard input is used for the HTML, so the two would clash
--title <text>✅ SupportedThe PDF Info dictionary; without it the <title> is used
--use-xserver❌ Not supportedThere is no dependency on an X server
-V, --version✅ Supported

Default margins: wkhtmltopdf uses 10mm left and right and leaves top and bottom unset, while sghtmltopdf currently defaults to 96px, that is 1in or 25.4mm, on all four sides. The default is not being changed, so that existing output stays as it is. State --margin-* explicitly when you move across.

Outline Options

PDF outlines, that is bookmarks, are not supported at all, so nothing in this section is. A table of contents inside the document can be built with --toc.

OptionRationaleNotes
--outline, --no-outline❌ Not supportedPDF bookmarks are not implemented
--outline-depth <level>❌ Not supportedAs above
--dump-outline <file>❌ Not supportedAs above
--dump-default-toc-xsl❌ Not supportedXSLT is not used

Page Options

OptionRationaleNotes
--allow <path>✅ SupportedThe directories local reads are confined to; it matters most in server mode
--background, --no-background✅ Supported
--bypass-proxy-for <value>❌ Not supportedProxies are not supported
--cache-dir <path>❌ Not supportedThere is no fetch cache; one can be added if it turns out to be needed
--checkbox-checked-svg, --checkbox-svg, --radiobutton-checked-svg, --radiobutton-svg❌ Not supportedSVG cannot be drawn. Form controls are drawn with built-in shapes instead
--cookie <name> <value>❌ Not supportedAuthenticated fetching is out of scope
--custom-header <name> <value>, --custom-header-propagation❌ Not supportedAs above
--debug-javascript, --no-debug-javascript❌ Not supportedJavaScript is not supported
--default-header✅ SupportedA default header with the document name and page number; a shortcut for the simple header options
--encoding <encoding>✅ SupportedThe order is BOM, --encoding, <meta charset>, then UTF-8
--disable-external-links, --enable-external-links✅ SupportedLink annotations
--disable-forms, --enable-forms❌ Not supportedFillable PDF forms (AcroForm) are never produced
--images, --no-images✅ Supported
--disable-internal-links, --enable-internal-links✅ Supported
-n, --disable-javascript, --enable-javascript❌ Not supportedExecuting JavaScript is a deliberate non-goal
--javascript-delay <msec>❌ Not supportedAs above
--keep-relative-links, --resolve-relative-links✅ SupportedHow link annotation URLs are resolved, implemented together with <base href>
--load-error-handling <handler>✅ Supportedabort and ignore. There is no skip, since there is only one input
--load-media-error-handling <handler>✅ SupportedFailures to fetch images, fonts, and stylesheets
--disable-local-file-access, --enable-local-file-access✅ SupportedArranged alongside the existing --allow-remote-assets
--minimum-font-size <int>✅ Supported
--exclude-from-outline, --include-in-outline❌ Not supportedMeaningless when there is only one input
--page-offset <offset>✅ SupportedWhere page numbering starts
--password, --username❌ Not supportedHTTP authentication is out of scope
--disable-plugins, --enable-plugins❌ Not supportedThere is no plugin mechanism
--post <name> <value>, --post-file <name> <path>❌ Not supportedPOSTing when the input is a URL is out of scope
--print-media-type, --no-print-media-type❌ Not supportedPrint media is always assumed
-p, --proxy <proxy>, --proxy-hostname-lookup❌ Not supportedProxies are not supported
--run-script <js>❌ Not supportedJavaScript is not supported
--disable-smart-shrinking, --enable-smart-shrinking❌ Not supportedA shrinking strategy specific to WebKit
--ssl-crt-path, --ssl-key-password, --ssl-key-path❌ Not supportedClient certificates are out of scope
--stop-slow-scripts, --no-stop-slow-scripts❌ Not supportedJavaScript is not supported
--disable-toc-back-links, --enable-toc-back-links✅ SupportedLinks back from a heading to the table of contents
--user-style-sheet <path>✅ SupportedCSS in the user origin
--viewport-size <size>❌ Not supportedThere is no notion of a viewport
--window-status <status>❌ Not supportedJavaScript is not supported
--zoom <float>✅ Supported

Everything in this section is supported. Since JavaScript is not executed, the page variables that wkhtmltopdf passed as a query such as ?page=1&topage=5 on the --header-html URL, to be inserted by JavaScript, are handled by substituting placeholders as text.

OptionRationaleNotes
--header-left, --header-center, --header-right✅ SupportedMapped onto the @page margin boxes
--footer-left, --footer-center, --footer-right✅ SupportedAs above
--header-html <url>, --footer-html <url>✅ SupportedA separate HTML file is rendered into the margin area
--header-line, --no-header-line✅ Supported
--footer-line, --no-footer-line✅ Supported
--header-spacing <real>, --footer-spacing <real>✅ Supportedmm
--header-font-name, --header-font-size✅ Supported
--footer-font-name, --footer-font-size✅ Supported
--replace <name> <value>✅ SupportedReplaces [name] in the header or footer, mapping directly onto the placeholder scheme here

Of wkhtmltopdf’s built-in placeholders, the ones that work are [page], [frompage], [topage], [date], [time], and [title] with [doctitle]. [section] and [subsection], which name the nearest heading, and [webpage], [sitepage], and [sitepages], which are for multiple inputs, are not supported. Any other name can be defined with --replace.

TOC Options

The HTML structure and default styling of the generated table of contents follow what wkhtmltopdf’s default TOC XSL produces: nested <ul> for the levels, and <li><div><a>heading</a><span>page number</span></div></li> for each entry.

OptionRationaleNotes
--toc-header-text <text>✅ Supported“Table of Contents” by default; the text of the <h1>
--toc-level-indentation <width>✅ Supported1em by default; ul { padding-left }
--toc-text-size-shrink <real>✅ Supported0.8 by default; ul ul { font-size: 80% }
--disable-dotted-lines✅ SupportedOmits the border-bottom: dashed on the div
--disable-toc-links✅ SupportedOmits the <a href> links from the entries to the headings
--xsl-style-sheet <file>❌ Not supportedXSLT is not supported; change the appearance with --user-style-sheet

Options unique to sghtmltopdf

OptionWhat it does
--font <path>, --font-index <N>Names the fonts explicitly; optional and repeatable. Without it the system fonts are used
--gothic-font, --mono-font, --serif-font, each with an -indexNames the actual font behind the generic families sans-serif, monospace, and serif
--allow-remote-assetsAllows fetching absolute http(s) URLs
--streamingProcesses the input in streaming mode
--base-url <url|dir>The base for resolving relative references, for example when reading from standard input
--author, --subject, --keywordsThe PDF Info dictionary; wkhtmltopdf only had --title
--cover <path>, --tocThe cover and the table of contents; wkhtmltopdf used positional arguments
The server subcommandHTTP server mode