Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
HTML to PDF

How to Position a Table of Contents in wkhtmltopdf

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put toc in the command where you want the table of contents to appear. wkhtmltopdf writes document objects in command-line order, so wkhtmltopdf toc input.html output.pdf creates a front TOC, while wkhtmltopdf input.html toc output.pdf places it after the content. A cover remains outside the generated TOC: wkhtmltopdf cover cover.html toc input.html output.pdf.

Position the TOC by changing object order

wkhtmltopdf treats a table of contents as a document object, not as HTML that is automatically inserted into your page. The objects are written to the output PDF in the order specified on the command line. This rule controls placement.

Front TOC without a cover

wkhtmltopdf toc input.html output.pdf

The toc object is first, so the generated contents pages precede the pages rendered from input.html.

TOC after the main document

wkhtmltopdf input.html toc output.pdf

Putting toc after the page object appends the contents to the end of the PDF. This is useful when the contents is intended as an index or reference section rather than front matter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Epson EcoTank ET-2800 Wireless Color All-in-One Supertank Printer - Black
  • INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
  • COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
  • ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
  • HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs

Cover, then TOC, then content

wkhtmltopdf cover cover.html toc input.html output.pdf

A cover object is rendered first, the TOC follows it, and the content comes last. The cover is excluded from the generated TOC. For a book assembled from several page objects, keep the same principle: list cover, toc, and each content object in the exact order you want them printed.

Content followed by a back-of-book TOC

wkhtmltopdf cover cover.html chapters-1.html chapters-2.html toc book.pdf

Here the TOC is generated after all chapter objects. Headings from the input page objects are used to build the entries; the cover still does not become an entry.

Make sure the headings you expect are detected

wkhtmltopdf builds the TOC from heading tags in the input documents. Use semantic h1 through h6 elements instead of styling ordinary paragraphs to look like headings.

<h1>Installation</h1>
<h2>Linux packages</h2>
<h2>Windows installer</h2>
<h1>Configuration</h1>

The heading levels form the hierarchy shown in the contents. Keep levels logically nested: an h2 should normally belong to the preceding h1, and an h3 to the preceding h2. If an expected entry is missing, inspect the actual rendered HTML and confirm that the element is a real heading in the document object being converted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Epson EcoTank Photo ET-8550 Wireless Wide-Format All-in-One Tank Printer
  • CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
  • INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
  • PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
  • ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴

Inspect the detected outline before styling

Use --dump-outline to see what wkhtmltopdf detected. This separates an outline or heading problem from a visual styling problem. Once the outline contains the expected titles and nesting, adjust indentation, links, or typography.

Separate visual depth from PDF outline depth

--outline-depth <level> limits the depth of the PDF viewer’s outline (bookmark) tree. It does not change the indentation or text-size treatment of the printed TOC. Configure the two independently when you want detailed printed contents but a shallower bookmark panel, or the reverse.

Use the built-in TOC styling options

These switches affect the default TOC stylesheet. Put TOC-specific options in the TOC object area when using per-object options; keep global settings such as page size, orientation, and margins in the global area required by the command synopsis.

Option Purpose Default or effect
--toc-header-text <text> Changes the heading printed above the contents Default is Table of Contents
--toc-level-indentation <width> Sets the indentation applied for each deeper heading level Default is 1em; for example, use 1.5em for a wider hierarchy
--disable-dotted-lines Removes the leader dots between an entry and its page number Dotted leaders are shown unless disabled
--disable-toc-links Removes links from TOC entries to their sections Entries are linked by default
--toc-text-size-shrink <real> Scales text at each deeper heading level Default is 0.8
--outline-depth <level> Limits the PDF bookmark outline Applies to the viewer outline, not printed TOC indentation

A front TOC with a custom title and no leaders

wkhtmltopdf 
  --toc-header-text "Contents" 
  --toc-level-indentation 1.5em 
  --disable-dotted-lines 
  toc chapters.html book.pdf

This keeps clickable entries, changes the heading to “Contents,” increases each level’s indentation, and removes the dotted leaders. Add --disable-toc-links only when you deliberately need a non-interactive contents page.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
HP Smart Tank 5000 Wireless All-in-One Ink Tank Printer, Scanner, Copier with 2 Years of Ink Included, Best-for-Home, Cartridge-Free, Refillable and AI-Enabled. (5D1B6A)
  • SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
  • INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
  • KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster
  • THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.

Why a flag may appear to do nothing

The built-in switches style the default stylesheet. If you supply --xsl-style-sheet, your custom XSLT controls the generated markup and presentation, so the default TOC flags no longer apply. Check for an active custom stylesheet before changing command-line values repeatedly.

Use XSLT when the default layout is not enough

wkhtmltopdf generates the TOC by transforming an outline XML document with XSLT. This is the extension point for a different title position, custom fonts, bespoke leader behavior, extra columns, or CSS that the built-in flags cannot express.

Export the default stylesheet

wkhtmltopdf --dump-default-toc-xsl > toc.xsl

Edit toc.xsl and its CSS rather than starting from an empty transform. The default file shows the expected templates and makes it easier to preserve page-number and link behavior while changing appearance.

Inspect the outline XML

wkhtmltopdf --dump-outline outline.xml toc input.html output.pdf

The outline namespace is http://wkhtmltopdf.org/outline. Each item can contain nested items and carries title, page, link, and backLink attributes. Use these values in the XSLT to decide what is printed and where links point.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
NDYIN Portable Printers Wireless for Travel, N80 Bluetooth Thermal Printer
  • Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
  • No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
  • Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
  • Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
  • The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art

Apply the custom stylesheet

wkhtmltopdf toc --xsl-style-sheet toc.xsl input.html output.pdf

With a custom transform, implement indentation, font-size changes, dotted leaders, forward links, and back links in XSLT/CSS. Do not expect --toc-header-text, --toc-level-indentation, or the other default-style flags to alter the custom result.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Control TOC behavior from libwkhtmltox

If you embed wkhtmltopdf through libwkhtmltox instead of invoking the executable, create a TOC object between the relevant page objects. The TOC object exposes settings for caption text, indentation, dotted-line behavior, forward and back links, and font scaling. Object settings also include includeInOutline, pagesCount, and tocXsl.

Use the same conceptual model as the CLI: object insertion order controls physical position, heading tags control entries, and tocXsl switches from the default stylesheet to your own XSLT. Keep page size, orientation, and margins at the global or page-object level so the TOC has enough printable width.

Or skip the browser setup

If your real task is obtaining a clean image or PDF of a web page rather than assembling a multi-object document, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for authentication, output formats, and the complete option set.

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo also supports full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets plus custom viewports, retina scale, PDF paper and margin controls, custom CSS and JavaScript, click-before-capture actions, selector waits, network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable caching TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs are accepted to ease migration.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to start without a card.

Quick Recap

Troubleshoot placement, entries, and appearance

The TOC is at the wrong end

  • Cause: toc is in the wrong position among cover and page objects.
  • Fix: Move the token itself. Use cover toc chapters.html for cover-then-front-matter, or put toc after the final content object for a back TOC.

The cover appears as a TOC entry

  • Cause: The cover was supplied as an ordinary page object or its content was duplicated in the chapter HTML.
  • Fix: Pass it with the cover object syntax and keep cover-only headings out of the content documents used to build the outline.

Headings are missing

  • Cause: The text is styled as a paragraph, is outside the converted document object, or uses malformed heading markup.
  • Fix: Use valid h1–h6 tags, then run --dump-outline and inspect the resulting hierarchy before changing CSS.

Indentation or text shrink has no effect

  • Cause: A custom XSLT stylesheet is active.
  • Fix: Remove --xsl-style-sheet to test the default stylesheet, or implement the desired change directly in your XSLT and CSS.

Links do not work

  • Cause: --disable-toc-links was supplied, or the custom XSLT omitted the generated link and back-link attributes.
  • Fix: Remove the disabling flag for the default stylesheet. In custom XSLT, preserve the link and backLink values from each outline item.

The TOC is clipped or wraps unexpectedly

  • Cause: Global page size, orientation, or margins leave insufficient printable width.
  • Fix: Increase the usable page width, choose a suitable orientation, or shorten long headings. Apply these as global rendering settings rather than trying to solve a page-margin problem with indentation alone.

The command behaves differently across machines

  • Cause: Different wkhtmltopdf builds expose different patched-Qt capabilities.
  • Fix: Record and compare wkhtmltopdf --version, verify that the binary supports the TOC features you use, and test the same input with the same page size and margins.

Practical checks before shipping the PDF

  1. Run a minimal front-TOC command with one known h1 and one h2.
  2. Confirm object order, especially when a cover or multiple chapter files are present.
  3. Inspect the outline with --dump-outline if an entry or nesting level is wrong.
  4. Choose default flags for straightforward title, indentation, dots, links, and scaling changes.
  5. Move to XSLT only when the required layout is outside those flags, and then style every desired behavior in the custom transform.
  6. Check the final PDF in a viewer: printed contents pages, bookmark depth, internal links, page numbers, margins, and clipping can be affected independently.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.