October 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 ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
JavaScript

How to Make wkhtmltopdf Wait for jQuery’s Ready Event

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

Set a sentinel such as window.status = 'ready' only after jQuery’s ready callback and all later rendering work have finished, then run wkhtmltopdf with --window-status ready. This event-driven approach is more reliable than guessing a fixed delay, but jQuery’s ready event alone does not wait for images or asynchronous work such as AJAX requests.

Make wkhtmltopdf wait for a completion signal

wkhtmltopdf can wait until a page sets window.status to a value you choose. Put that assignment at the point where the page is genuinely ready to print—not merely at the start of a callback—and pass the same value to --window-status.

Minimal jQuery example

<script>
$(function () {
  // Finish DOM updates, charts, AJAX-driven rendering, and other page work here.
  window.status = 'ready';
});
</script>

Save the page or add the script to the page that wkhtmltopdf loads, then run:

wkhtmltopdf --window-status ready https://example.com/report.html report.pdf

The option’s value must match the assigned status exactly, including capitalization. You may choose a different sentinel—for example, pdf-ready—as long as both sides use the same string. The command-line option tells wkhtmltopdf to wait until the browser page’s status equals that value before printing.

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

Put the signal at the real end of rendering

The minimal snippet works only if everything the PDF needs has already been rendered when the ready callback runs. If the page starts asynchronous work there, signal completion from the final completion path instead. Otherwise wkhtmltopdf may see the sentinel while the chart, table, or other content is still missing.

<script>
$(function () {
  $.ajax({ url: '/report-data' })
    .done(function (data) {
      renderReport(data);
      window.status = 'ready';
    })
    .fail(function () {
      // Choose an explicit failure policy for your application.
      window.status = 'report-error';
    });
});
</script>

This example signals success only after the response has been rendered. Decide what your own application should do on failure: it can show an error page, set a separate error sentinel, or leave the success sentinel unset so a caller-side timeout can detect that the expected state was never reached. Do not label a failed or incomplete report as ready.

Or skip the browser setup

If your goal is to capture a page as an image or PDF rather than to run wkhtmltopdf specifically, ScreenshotNeo offers a website screenshot API and MCP server. It is a different workflow, not a wkhtmltopdf flag: make one GET request with the URL, and it can return a PNG, JPEG, WebP, or PDF. Cookie banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. An MCP server lets AI agents use its screenshot tools. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

For example, use cURL to request a WebP capture of the report page:

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⁴
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/report.html -o shot.webp

See the ScreenshotNeo API documentation for request options and formats. To get started, sign up for 1,000 free screenshots a month with no card.

When a fixed JavaScript delay is appropriate

If you cannot change the page to set a status signal, or its rendering time has a dependable upper bound, use --javascript-delay to wait a fixed number of milliseconds after page loading:

wkhtmltopdf --javascript-delay 2000 https://example.com/report.html report.pdf

The wkhtmltopdf documentation describes --javascript-delay <msec> as a fixed wait for JavaScript, with a documented default of 200 ms. Its library settings describe load.jsdelay as the time to wait after page loading before printing, or until JavaScript calls window.print(). A 2,000 ms delay is an example, not a universal recommendation: choose a value based on the page and conditions you actually need to support.

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.

A delay is a timing estimate, not evidence that work has completed. If a request or chart sometimes takes longer than the chosen interval, the output can still be incomplete. A long delay also makes every capture wait, including captures where the page finishes quickly. When you control the page, an explicit completion signal tied to the final rendering step is generally the clearer contract.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach What determines when printing begins Best fit Main limitation
--window-status ready The page sets window.status to the specified sentinel. Pages you can change, with a meaningful completion event. The signal must be reachable and set at the correct point; reported build and option-order issues mean the exact command should be tested.
--javascript-delay 2000 A fixed number of milliseconds after page loading; 200 ms is the documented default. Pages you cannot instrument, where a wait is an acceptable estimate. It can wait too long or print too early when rendering time varies.

Understand what jQuery ready does—and does not—mean

jQuery’s document-ready callback runs when the DOM hierarchy has been constructed. It does not mean that every image has loaded, and it does not wait for application work that continues after the callback begins. The browser’s window load event waits for assets such as images, but even that is not a substitute for waiting on later work your application starts separately.

Images and other page assets

If the PDF needs images that are still loading after DOM readiness, do not set the status sentinel immediately inside $(function () { ... }). Arrange for the signal to be set after the required assets have completed. Be specific about which assets matter: waiting for every optional third-party resource can make printing fragile, while signaling before a required report image is ready can leave a blank area.

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

AJAX, charts, and deferred rendering

For data-driven pages, set the status after the final response has been handled and the resulting DOM updates or chart draw have finished. If rendering itself is asynchronous, the end of the AJAX callback may still be too early; use the chart or rendering library’s completion callback when it provides one. The important condition is that the final content is visible to the page before the sentinel changes.

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

Troubleshoot an early, missing, or stuck PDF

--window-status has documented issue reports involving signals that appeared to be ignored, a command that did not return when the option was combined with --javascript-delay, and behavior affected by argument ordering around toc. These reports do not establish that every build has the same fault. They do mean that you should verify the exact binary and invocation used in your environment rather than assume that a working command on one machine proves another build behaves identically.

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.

Check the executable and reduce the test case

  1. Run wkhtmltopdf --version and record the result. The project downloads page identifies the 0.12.6 series as stable and gives its release date as June 11, 2020; confirm the version installed in your own environment rather than inferring it from the download page.
  2. Create a minimal HTML file that sets window.status = 'ready' from a short timer, then run wkhtmltopdf against that local file with --window-status ready. This separates basic option behavior from jQuery, remote scripts, and application code.
  3. If the minimal page succeeds, add the real jQuery include and ready handler, then add asynchronous rendering one step at a time. This helps identify whether the issue is the option, script loading, or an application completion path.
  4. Use --debug-javascript while diagnosing JavaScript errors. Check that jQuery loads successfully before the handler runs and that the assignment is reachable.
  5. Temporarily remove other options, especially toc and a simultaneous --javascript-delay, then restore them individually. Keep the final argument order that you have tested with your exact binary.

Match the symptom to a likely cause

  • The PDF is missing late content: the sentinel is probably set before an AJAX response, chart draw, asset load, or other render step finishes. Move it to the final completion path.
  • wkhtmltopdf waits indefinitely: the page may never set the expected string because of a script error, an unavailable script, or an error path that skips the success assignment. Check the spelling on both sides and inspect JavaScript diagnostics.
  • The option seems ignored: reproduce with the timer-based minimal file, then compare its result with the production command. Record the version and test without other options before changing the page’s timing logic.
  • The behavior changes when options are combined: test the invocation without --javascript-delay and without toc, then add options back one at a time. Treat the exact binary and command line as part of the issue.
  • The page works locally but not in deployment: provide the project’s support channels with the wkhtmltopdf version, operating system and version, and a minimal HTML/CSS/JavaScript reproduction. A small reproducible case is more useful than a full application whose dependencies obscure the cause.

Account for version, compatibility, and security

The wkhtmltopdf project’s downloads page lists the 0.12.6 series as stable, released June 11, 2020. Its status page says wkhtmltopdf depends on the WebKit1 in-process API and recommends evaluating Puppeteer for sites using dynamic JavaScript, or WeasyPrint and the commercial Prince engine for controlled report generation. For a new system with substantial modern JavaScript, assess whether wkhtmltopdf’s rendering engine is suitable before trying to compensate for compatibility problems with longer waits. For controlled, mostly static reports, compare WeasyPrint or Prince against your layout requirements.

Waiting for a jQuery callback does not upgrade the browser engine or guarantee that a modern site’s scripts will work. If JavaScript compatibility is the underlying problem, changing from a status signal to a longer delay will not fix it. Test the actual pages, assets, fonts, and output layout your workflow depends on.

Security is a separate concern from readiness. The project warns against using wkhtmltopdf with untrusted HTML and JavaScript without sanitization because that can enable complete server takeover. Treat the HTML source, local-file access, network access, and process isolation as deployment boundaries. Do not expose a renderer with broad server permissions to arbitrary user-controlled page content.

Quick Recap

Choose the wait strategy for the job

  • Use --window-status when you control the page and can set the sentinel after the last required render step.
  • Use --javascript-delay when instrumentation is not possible and a fixed wait is an acceptable trade-off, while recognizing that it cannot prove completion.
  • Test the precise executable, operating system, and full option combination you will deploy; keep a minimal reproduction alongside production diagnostics.
  • Evaluate a different renderer if the requirement depends on JavaScript behavior that wkhtmltopdf’s WebKit1-based engine does not handle reliably.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair 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.