October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk7 min

How wkhtmltopdf Uses Qt Media Print Styles

A practical guide to wkhtmltopdf's --print-media-type option, CSS cascade behavior, legacy Qt/WebKit limits, security, troubleshooting and alternatives.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Short answer: add --print-media-type when you want wkhtmltopdf to evaluate CSS for the print media type instead of its default screen media type. Rules inside @media print can then apply, while ordinary (unqualified) rules remain part of the cascade unless another rule overrides them. The switch selects a media context; it does not repair missing stylesheets, inaccessible assets, unsupported CSS, or every layout problem.

What --print-media-type actually changes

wkhtmltopdf renders HTML through a Qt/WebKit-based engine. Its command-line manual documents --print-media-type as selecting print media instead of screen media, and lists --no-print-media-type as the default. In practical terms, the converter asks CSS to resolve as though the document were being printed.

That matters for media queries such as:

/* Used in every media context unless overridden */
body {
  color: #222;
  font: 14px/1.5 Arial, sans-serif;
}

@media print {
  body {
    color: #000;
  }

  .screen-only {
    display: none;
  }
}

@media screen {
  .print-only {
    display: none;
  }
}

With the default screen context, the @media screen block is eligible and the @media print block is not. With --print-media-type, the reverse media-specific choice is made. The unqualified body declarations are still eligible in both contexts; normal CSS specificity, source order and inheritance determine which declaration wins.

Therefore, you do not normally need to copy every general rule into @media print. Put shared declarations outside a media query and use @media print only for print-specific changes. If a declaration appears to disappear, investigate the cascade, stylesheet loading and the particular wkhtmltopdf build before assuming that the option intentionally removes unqualified CSS.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Basic commands

Render using print media

wkhtmltopdf --print-media-type input.html output.pdf

Use the default screen media behavior

wkhtmltopdf --no-print-media-type input.html output.pdf

Use a file URL, an HTTP(S) URL or standard input as your source, provided the input’s resources are reachable by the converter. Keep the output extension consistent with the intended result.

A minimal reproducible test

  1. Create an HTML file containing one unqualified rule, one @media screen rule and one @media print rule.
  2. Convert it once with --no-print-media-type and once with --print-media-type.
  3. Compare only the declarations controlled by those media blocks.
  4. Then add your real external stylesheets, images and scripts one at a time. This identifies whether the difference comes from media selection or resource loading.

How CSS is expected to behave

Unqualified rules

A selector outside @media is not “screen-only” merely because the default conversion uses screen media. It is a normal rule that can participate in the cascade for the selected media. For example, a global margin, font family or table border should remain available when print media is selected unless a later, more specific rule changes it.

Print-only rules

Rules enclosed by @media print are intended for printed output. Common uses include hiding navigation, removing interactive controls, changing colors for paper and adjusting page breaks:

@media print {
  nav,
  .toolbar,
  .chat-widget {
    display: none;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  .avoid-break {
    page-break-inside: avoid;
  }
}

Screen-only rules

Rules inside @media screen are not selected when the converter is told to use print media. If a layout depends on screen-only declarations, supply an equivalent print rule or move the shared portion outside the media query.

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

Why a print conversion can still look wrong

The media switch does not guarantee support for every modern CSS feature. The wkhtmltopdf project status page describes its Qt 4/WebKit stack as old: Qt 4 has not been supported since 2015, and the WebKit in Qt 4 had not been updated since 2012. Treat those as project-reported compatibility facts, not as a promise that a current desktop browser will match the PDF.

Rank #2
Sale
Adobe Acrobat 6 PDF For Dummies
  • Used Book in Good Condition

Diagnosing the “print rules work, ordinary styles vanish” report

A historical 2015 user question described print rules appearing while styles without an explicit media type seemed to be ignored. That report is a user’s unresolved question, not authoritative evidence that wkhtmltopdf is supposed to discard unqualified CSS. Work through the following checks instead.

1. Confirm the binary and option

Run the exact executable used by your application and record its version:

wkhtmltopdf --version

Different packages may be patched builds with different Qt behavior. Make sure the command shown in logs really includes --print-media-type and is not being replaced by a wrapper’s defaults.

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

2. Check stylesheet URLs and paths

Open the source URL from the same machine and user account that runs wkhtmltopdf. Verify that linked CSS files return successfully, that relative paths resolve from the expected document location, and that HTTPS certificates, authentication and redirects are acceptable to the converter. For local files, use correct file:/// URLs and make any required local-file access setting explicit in your deployment policy.

3. Inspect the cascade

Look for a later rule, a more specific selector, an inline style or an !important declaration that overrides the apparently missing property. Also check whether a parent has display:none, zero dimensions or an inherited color that makes a child appear absent.

4. Reduce the document

Remove JavaScript, frameworks and unrelated stylesheets until a small HTML file reproduces the problem. Add resources back incrementally. This distinguishes a media-query issue from malformed markup, timing, a blocked request or unsupported layout code.

5. Check JavaScript timing

If CSS classes or content are added by JavaScript, make sure the page has finished its work before conversion. A print media selection cannot make a script run earlier or make a failed network request succeed.

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

What the setting does not affect

It does not apply to wkhtmltoimage

The C API documentation describes load.printMediaType as selecting print media instead of screen media and explicitly says that the setting has no effect for wkhtmltoimage. The documented behavior is therefore specific to page loading for PDF conversion, not a universal switch for every wkhtml family tool.

It does not modernize WebKit

Choosing print media does not add support for newer browser APIs, CSS layout engines or JavaScript features. If your source requires a current browser engine, evaluate a tool whose renderer matches that requirement.

It does not make untrusted HTML safe

The wkhtmltopdf project status page warns: “Do not use wkhtmltopdf with any untrusted HTML – be sure to sanitize any user-supplied HTML/JS, otherwise it can lead to complete takeover of the server it is running on!” Sanitize user content, isolate conversion workers and restrict network and filesystem access according to your threat model.

Reliable print CSS patterns for wkhtmltopdf

Keep shared styles shared

/* Shared */
.invoice {
  width: 100%;
  border-collapse: collapse;
}

/* Print adjustments */
@media print {
  .invoice {
    font-size: 11pt;
  }

  .invoice thead {
    display: table-header-group;
  }
}

Use explicit print overrides

When a screen rule sets a dark background, animation or fixed positioning, override that property in @media print rather than duplicating the entire stylesheet. Keep selectors at comparable specificity so the intended print declaration wins predictably.

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

Make page boundaries deliberate

Use the page-break properties supported by your wkhtmltopdf build, test long tables and avoid relying solely on modern fragmentation properties. A rule that works in a current browser may be ignored or interpreted differently by the legacy engine.

Alternatives when the renderer is the constraint

The project’s status page suggests different alternatives for different workloads: WeasyPrint or Prince for controlled HTML report generation, and Puppeteer for sites that require dynamic JavaScript. Those are project suggestions, not a head-to-head benchmark. Choose based on required CSS support, JavaScript execution, deployment security and—where applicable—commercial licensing and maintenance.

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

Or skip the browser setup

If your goal is simply to obtain a clean screenshot or PDF of a URL rather than maintain a wkhtmltopdf rendering stack, ScreenshotNeo provides a single HTTP request. Its API accepts the URL and can return PNG, JPEG, WebP or PDF. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled.

Only clean shots are billed. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers report the page verdict and billing state. ScreenshotNeo also offers an MCP server for Claude, Cursor and other MCP clients, with take_screenshot, get_page_info and capture_pdf tools.

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

One-call examples

See the full parameter reference in the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

All features are included on every plan. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

Troubleshooting checklist

Symptom Likely cause Action
Print-specific declarations never appear The command uses the default screen media or the declaration is overridden. Confirm --print-media-type, inspect specificity and test a minimal file.
General declarations seem missing Stylesheet failed to load, paths resolve incorrectly, or a later rule overrides them. Check URLs, redirects, credentials, logs and the cascade.
PDF differs from a modern browser Legacy Qt/WebKit support. Simplify CSS or evaluate WeasyPrint, Prince or Puppeteer for the workload named by the project.
Dynamic content is absent JavaScript did not finish or a request was blocked. Verify timing and network access; media selection does not fix asynchronous loading.
Image output ignores the setting The C API documents no effect for wkhtmltoimage. Do not rely on this option for image conversion; apply image-specific testing or choose a different renderer.

Practical decision guide

  • Use --print-media-type when your document has intentional @media print rules and you want those rules selected for PDF output.
  • Keep shared CSS outside media queries and add focused print overrides.
  • Investigate resource loading, cascade order, version and JavaScript timing before treating unqualified CSS as unsupported.
  • Use a modern or specialized renderer when the legacy Qt/WebKit engine cannot provide the CSS or JavaScript behavior your document needs.
  • Sanitize and isolate any conversion involving user-controlled HTML or JavaScript.

Frequently Asked Questions

Is --print-media-type enabled by default?

No. The wkhtmltopdf manual lists --no-print-media-type as the default; pass --print-media-type to select print media.

Do all styles need to be placed inside @media print?

No. Ordinary rules remain eligible for the selected media context. Put only print-specific changes in @media print, then verify the cascade and stylesheet loading if a shared rule appears absent.

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

Does the option change wkhtmltoimage output?

The C API documentation says load.printMediaType has no effect for wkhtmltoimage.

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.

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.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.