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

You cannot pass arbitrary HTML source as a normal positional argument to the wkhtmltopdf command-line tool. Its documented page input is a URL or a file name. For a string your application already has, write the HTML to a temporary or managed .html file, then give that file to wkhtmltopdf. If you need to render HTML held in memory, use a library or wrapper that explicitly accepts HTML content. Do not confuse that with the CLI’s --read-args-from-stdin option: it reads command-line arguments, not the page’s HTML source.

Use a file for the command-line tool

The CLI pattern is an input page—either a URL or a file name—followed by the output PDF path. Save the string as a complete HTML document, then pass its path as the input. This works whether the HTML was typed by hand, loaded from a database, or generated in application code.

cat > /tmp/document.html <<'HTML'
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>
  <h1>Hello</h1>
  <p>HTML content</p>
</body>
</html>
HTML

wkhtmltopdf /tmp/document.html /tmp/document.pdf

The heredoc is convenient for a shell example. In an application, use the language’s temporary-file facilities rather than interpolating untrusted text into a shell command. Write with a known encoding, close or flush the file before launching the renderer, check the process exit status, and remove the temporary file when it is no longer needed.

When the HTML is already in a variable

The same approach applies: write the string to a file, then run the CLI with that file path. Prefer passing arguments as an array through a process API instead of composing a shell command. This avoids shell-quoting bugs in paths and reduces command-injection risk. A library or wrapper is another option if it documents an HTML-content input; confirm which interface it exposes rather than assuming CLI behavior applies to it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Why stdin options are easy to misread

--read-args-from-stdin is for feeding lines of command-line arguments to the program, with each line acting as a separate invocation. It does not tell the CLI to treat a stream of HTML bytes as the input page. The project’s library settings documentation describes - as a possible page URL or path when stdin is used, but that is documentation for the library API, not evidence that a raw HTML string can be supplied as a normal positional argument to the CLI.

Use the file method for the documented CLI workflow. If you choose a library’s stdin/content interface, consult the documentation for that exact library and version, and test its input and resource-resolution behavior separately.

Make encoding and assets resolve correctly

Keep the character encoding consistent

For non-ASCII text, align three things: the bytes written to the file, the HTML’s declared charset, and wkhtmltopdf’s input encoding option. For example, if the file is UTF-8, declare UTF-8 in the document and specify the matching value with --encoding:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
wkhtmltopdf --encoding utf-8 /tmp/document.html /tmp/document.pdf

The option controls the default input text encoding; it does not repair a file written in a different encoding. If accented characters, symbols, or non-Latin text appear incorrectly, inspect the actual bytes and the declaration as well as the command.

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.

Account for the new base location

Relative CSS, image, and font paths are resolved in the context of the input page. Writing HTML to a temporary directory can therefore change where a relative reference points. A stylesheet reference such as styles/main.css may no longer be next to the HTML file, even if it worked in the original application context.

  • Use absolute resource URLs when the renderer can reach them.
  • Place the generated HTML near the referenced assets when local relative paths are needed.
  • Where the application or wrapper supports a base URL, set it deliberately so relative references resolve from the intended location.
  • For local resources, grant access only to the required paths. The manual documents --allow <path> for a specified folder and --enable-local-file-access for allowing a local input page to read other local files.

The manual’s current text describes local file access as disabled by default unless explicitly allowed. Build and package behavior can differ, so check the installed binary’s help and version rather than relying on an option default from another environment.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Wait for JavaScript-rendered content

The command-line manual documents JavaScript as enabled by default and a JavaScript delay of 200 ms by default. That delay is an option default, not a guarantee that asynchronous scripts, remote API calls, fonts, or lazy-loaded elements will finish in time. If the HTML fills itself in after initial page load, the generated PDF may capture an incomplete state.

  • Use --disable-javascript if scripts should not run.
  • Increase --javascript-delay when a known, bounded delay is sufficient.
  • Use --window-status where the page can set a specific status after its required content is ready.

Choose a readiness condition based on the page’s actual behavior; adding an arbitrary delay can make conversion slower without making it reliable. Check the installed manual for the exact option syntax supported by your build.

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

Render untrusted HTML with containment

The wkhtmltopdf project warns against rendering HTML that is not explicitly trusted. HTML can reference local files or network resources, and the renderer processes that content. If user-supplied markup must be converted, treat the renderer as an exposed process: restrict filesystem and network access, run it with limited privileges, and apply operating-system containment.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The project’s AppArmor guidance notes that --disable-local-file-access blocks local filesystem access but may be bypassable if an attacker exploits a vulnerability in a prebuilt binary. It describes AppArmor as an additional containment layer. Do not rely on a single command-line flag as the entire security boundary; grant only the file and network permissions the conversion needs.

Troubleshoot common failures

Symptom Likely cause What to check
The command rejects the HTML string or treats part of it as an argument Raw markup was supplied where the CLI expects an input URL or file name. Write the document to a file and pass that file path as the input.
CSS, images, or fonts are missing Relative paths resolve from the generated file’s location, or local access is restricted. Check the resolved paths; use absolute URLs, put the file near its assets, set a supported base URL, or allow only the needed local folder.
Accented or non-Latin characters are corrupted The file bytes, HTML charset declaration, and input encoding do not agree. Write the intended encoding explicitly, declare it in the document, and match it with --encoding.
Dynamic content is absent or incomplete Rendering happened before the page’s scripts or asynchronous work finished. Inspect whether JavaScript is enabled and configure an appropriate delay or window-status condition.
Local resources cannot be read The installed build disallows local access by default, or the path is outside the permitted directory. Check the installed binary’s help; use the narrowest suitable --allow path or local-access setting.
A flag behaves differently on another machine Different wkhtmltopdf builds or package configurations can change available behavior. Compare the installed version and its own help output. The project manual identifies itself as wkhtmltopdf 0.12.6 with patched Qt.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability choices

For one-off or batch command-line conversion, file input is straightforward and makes the exact input inspectable. In an application, temporary files add filesystem writes and cleanup work; a content-aware library can avoid that step if its documented API fits your needs. Either way, conversion time and reliability depend on the page’s resources and scripts, not just the HTML string. Remote assets add network dependencies, while local assets require paths and permissions that remain valid in the renderer’s execution context.

For repeatable jobs, use a controlled output directory, unique temporary names, bounded process timeouts, and explicit error handling. Record the wkhtmltopdf version and arguments used so environment changes can be diagnosed. Do not assume the documented defaults are identical across every packaged binary.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Or skip the browser setup

If your actual task is capturing a live web page as an image or PDF—not converting an arbitrary HTML string—ScreenshotNeo is a different, API-based option. It does not replace the local-file workflow for HTML text. Its one-call API accepts a URL:

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 request options. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000 shots. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

Sources and version context

The wkhtmltopdf command-line manual describes the page-object input syntax and options discussed here and identifies itself as version 0.12.6 with patched Qt. The official project homepage describes wkhtmltopdf as an open-source command-line renderer using Qt WebKit; the project’s library settings documentation covers its separate page-input setting, and its AppArmor guidance covers containment for untrusted input. Consult the documentation and help output for the exact build installed in your environment.

Frequently Asked Questions

Is wkhtmltopdf still based on a modern browser engine?

The project homepage describes it as a Qt WebKit command-line renderer; do not assume its rendering behavior matches a current Chromium-based browser.

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

Can I pass an HTML string directly to ScreenshotNeo’s URL endpoint?

No. The endpoint described here takes a URL for a page capture; use wkhtmltopdf’s file workflow or a library that explicitly accepts HTML content when your source is a raw string.

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.