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

For HTML whose content is created or updated by JavaScript, use a browser rendering engine from Java. Playwright Java can navigate to a page, wait for the application-specific signal that its content is ready, and generate a PDF with Page.pdf(). A static HTML-to-PDF renderer is suitable only when the markup and CSS fit its supported subset; it cannot run the JavaScript that makes a dynamic page dynamic.

Choose a renderer that matches how your HTML is built

“Dynamic HTML” commonly means JavaScript changes the document after the initial HTML arrives—for example, a client-rendered application or a template populated in the browser. A renderer must execute that JavaScript and lay out the resulting page if those changes need to appear in the PDF. A library that only lays out supplied HTML cannot reproduce browser-side behavior.

Approach Best suited to Main consideration
Playwright Java Pages and templates that rely on browser JavaScript or modern browser layout Wait for the page-specific ready state and account for print CSS; PDFs use print media by default. Playwright Page API and navigation documentation.
OpenHTMLtoPDF Controlled, well-formed XHTML or limited HTML whose CSS fits its supported subset It does not run JavaScript and does not implement some modern standards, including flex and grid. OpenHTMLtoPDF project.
Adobe PDF Services Java SDK sample workflow Data-driven HTML templates in which JavaScript updates the DOM before conversion The documented sample shows the workflow; it does not establish current pricing, service limits, or comparative performance. Adobe PDF Services Java SDK samples.

For a live site or client-rendered page, start with Playwright. For a generated invoice or report with controlled markup, consider OpenHTMLtoPDF if you can keep the HTML and CSS within its documented capabilities. Adobe’s sample is another documented data-driven workflow, but the sample alone is not enough to assess service suitability or cost.

Convert dynamic HTML with Playwright Java

Playwright runs a real browser engine, so the page’s JavaScript can execute before printing. The key implementation decision is not merely when navigation completes: wait until the particular content your application needs in the PDF is present. A generic load event cannot guarantee that an application’s asynchronous data or client rendering has finished.

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.

1. Add Playwright to the Java project

Use the Playwright Java dependency appropriate to your build and project version. The Java API and setup instructions are maintained in the Playwright for Java documentation. The example below assumes Playwright is installed and its browser has been installed for the environment where the program runs.

2. Navigate, wait for a content signal, and print

This runnable method accepts the target URL, a CSS selector that appears when the required content is ready, and an output filename. Replace the selector with a stable element or application-specific readiness signal on your page. Set an appropriate navigation timeout and handle exceptions according to your application’s logging and retry policy.

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.options.LoadState;
import com.microsoft.playwright.options.WaitForSelectorState;
import java.nio.file.Paths;

public class HtmlToPdf {
  public static void main(String[] args) {
    String url = "https://example.com/report";
    String readySelector = "#report-ready";
    String output = "report.pdf";

    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().launch(
          new BrowserType.LaunchOptions().setHeadless(true));
      try {
        Page page = browser.newPage();
        page.navigate(url, new Page.NavigateOptions().setTimeout(60_000));
        page.waitForSelector(readySelector,
            new Page.WaitForSelectorOptions()
                .setState(WaitForSelectorState.VISIBLE)
                .setTimeout(30_000));

        page.pdf(new Page.PdfOptions()
            .setPath(Paths.get(output))
            .setFormat("A4")
            .setPrintBackground(true)
            .setPreferCSSPageSize(true));
      } finally {
        browser.close();
      }
    }
  }
}

The selector wait is an example of an application-specific readiness condition, not a universal selector name. If the page renders its important content through a different signal, wait for that instead. Use a bounded timeout so a missing element fails visibly rather than leaving a job waiting indefinitely. See the Page API for navigation, waiting, and PDF options.

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.

3. Set print layout deliberately

page.pdf() uses print CSS media by default. That means print-specific styles can differ from what a user sees in a screen browser. If the PDF must follow screen styles, emulate screen media before calling pdf(). Conversely, when printing is intended, inspect the page’s print rules and use CSS such as @page for document-specific layout.

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

Playwright’s PDF options include paper format or explicit dimensions, margins, background printing, and preference for the page’s CSS @page size. Choose one clear source of page sizing: set the PDF format, or prefer the CSS page size when the template controls it. Background graphics are not printed unless enabled. Headers, footers, paper ranges, and other options should be configured only when the application needs them; consult the API for the exact options supported by the Playwright version in use.

When a full-page capture is not the right PDF

A PDF is paginated, unlike a tall screenshot. A long page may span multiple pages, and print CSS can reflow or hide content. Design or select print styles for page breaks, repeated headers, margins, and content that should remain together. Verify representative outputs, especially for tables, charts, and content loaded below the fold.

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.

Use OpenHTMLtoPDF for controlled, static documents

OpenHTMLtoPDF can be a fit when Java receives well-formed XHTML or limited HTML and the document’s CSS stays within the renderer’s supported subset. The project describes support for a reasonable subset of well-formed XML/XHTML and some HTML5 with CSS 2.1. It explicitly does not execute JavaScript and lacks many modern standards, including flex and grid layout. If a page needs client-side rendering, those limitations are decisive: render it in a browser first rather than expecting OpenHTMLtoPDF to run its scripts.

For this route, build the final document content in Java or provide already-populated markup, keep the CSS compatible with the renderer, and follow the project’s current documentation for its Java dependencies and conversion API. Do not select it on the assumption that it reproduces a contemporary website exactly; validate the required layout and features against the project’s documented subset.

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

Use Adobe’s documented data-driven sample when it fits

Adobe PDF Services’ Java SDK samples include a dynamic HTML workflow that uses provided data and JavaScript to update the HTML DOM before conversion. That establishes a documented route for data-driven templates. The cited sample does not establish current pricing, service limits, or comparative performance, so check the service’s current terms and technical requirements before choosing it for a production workload.

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

Common problems and how to fix them

  • The PDF is missing content rendered by JavaScript. The PDF call may have happened before the application updated the DOM, or a non-browser renderer may be in use. With Playwright, wait for a selector or other application-specific ready condition. With OpenHTMLtoPDF, supply the finished static content or choose a browser-based renderer.
  • The PDF looks different from the browser window. Playwright prints using print media by default. Review print styles, or call media emulation for screen styles before generating the PDF. Check page size and margins as well.
  • Colors or backgrounds are absent. Enable background printing in the PDF options and verify that the stylesheet’s print rules do not remove the relevant styling.
  • The program times out waiting for a selector. Confirm the selector exists on the final page, is visible in the expected state, and is not inside a frame or a different route. Increase the timeout only if the application legitimately needs more time; do not replace a meaningful readiness check with an arbitrary long sleep.
  • Modern layout collapses in a JVM renderer. Check whether the markup relies on unsupported CSS such as flex or grid. Use simpler supported styles or switch to a browser renderer.
  • The browser does not launch in the deployment environment. Confirm the Playwright browser installation is available to the runtime and that the environment permits the required browser process. Keep browser creation and closure within a controlled lifecycle, and inspect the Playwright setup documentation for environment-specific requirements.
  • Pages break in awkward places. Adjust print CSS, page dimensions, margins, and page-break behavior. Inspect the PDF at the target paper size rather than assuming screen layout maps directly to pages.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

The documented capabilities establish functional differences, not a universal performance or cost winner. A browser renderer has to launch or reuse a browser process and allow the page to reach a suitable state; design lifecycle and concurrency around your workload, and avoid closing a shared browser before its pages finish. A constrained JVM renderer may be preferable for predictable static templates if its CSS support is sufficient. For a hosted PDF service, assess current pricing, limits, data handling, and deployment needs directly; the sample workflow does not answer those questions.

For reliability, make readiness explicit, set timeouts, record failures with the URL and relevant job context, and validate PDFs from representative pages. Treat navigation success and content readiness as separate checks. A page can load successfully while its data request or client rendering is still pending.

Or skip the browser setup

If your actual goal is a screenshot of a web page rather than a paginated PDF, ScreenshotNeo offers a one-request screenshot API. For PDF output, its capture options include PDF settings; it is not a Java PDF library, so use the browser workflow above when Java must own the rendering process.

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.
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.

cURL example, documented at ScreenshotNeo API docs:

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

The endpoint returns an image or PDF according to the request’s output settings. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; those steps can each be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides screenshot and page-info tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Playwright Java execute page JavaScript before creating a PDF?

Yes. Playwright uses a browser engine; wait for the content your application needs before calling the PDF method.

Can OpenHTMLtoPDF render a JavaScript-driven website?

No. Its project documentation says it does not run JavaScript.

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

Is there a universal wait event that guarantees a dynamic page is ready?

No. Use a page-specific selector or application readiness signal for the content that must appear.

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.