Use iText pdfHTML when you need the documented URL-to-PDF path: create a java.net.URL, open its stream, and pass that InputStream to HtmlConverter.convertToPdf. The converter host must be able to reach the URL and any referenced assets. This produces a PDF from the HTML the renderer can process; it is not a guarantee of pixel-identical browser output, especially for JavaScript-heavy pages.
Minimal iText example: URL directly to a PDF
Add iText Core and pdfHTML using the dependency instructions for the version you have selected, then run this Java class. The URL is fetched by the JVM, and the response is written to output.pdf.
import com.itextpdf.html2pdf.HtmlConverter;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
public class UrlToPdf {
public static void main(String[] args) throws Exception {
URL page = new URL("https://example.com/");
try (InputStream html = page.openStream();
OutputStream pdf = Files.newOutputStream(Path.of("output.pdf"))) {
HtmlConverter.convertToPdf(html, pdf);
}
}
}
The openStream() call supplies the HTML bytes to pdfHTML. Stylesheets, images, fonts, and other remote resources referenced by the document may require additional network requests, so a page with many images can take longer. A URL stream also does not prove that scripts ran or that a dynamically generated state was captured.
Resolve relative images and stylesheets with a base URI
Relative references such as images/logo.png need a base location. Set one in ConverterProperties; use the page’s directory or another location from which the renderer is allowed to load assets.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
public class UrlToPdfWithBase {
public static void main(String[] args) throws Exception {
URL page = new URL("https://example.com/reports/annual.html");
ConverterProperties properties = new ConverterProperties();
properties.setBaseUri("https://example.com/reports/");
try (InputStream html = page.openStream();
OutputStream pdf = Files.newOutputStream(Path.of("annual.pdf"))) {
HtmlConverter.convertToPdf(html, pdf, properties);
}
}
}
A base URI helps resolve relative resources; it does not bypass authentication, robots or network policy, nor does it make unsupported CSS or JavaScript work.
What the renderer can—and cannot—reproduce
Static, renderer-compatible HTML
Server-rendered markup with ordinary links, images, tables, and CSS is the most predictable input. Validate the resulting PDF with the exact pages and assets your application cares about. Missing fonts, blocked resources, malformed markup, and CSS outside the engine’s support can all change layout.
JavaScript and modern application pages
The URL example fetches HTML; it is not a browser session that waits for a framework to finish, clicks controls, or executes every client-side effect. OpenHTMLtoPDF documents support for well-formed XML/XHTML and some HTML5 with CSS 2.1-era layout, and explicitly warns that arbitrary modern HTML5 may need adaptation. Consequently, a page that looks correct in Chrome can still be incomplete or rearranged in a Java renderer. The available material does not establish which library reproduces JavaScript-heavy pages best, so test your real target rather than relying on a generic ranking.
Rank #2
When to pre-render or adapt
- Render the page on your server and expose stable HTML when content is assembled in the browser.
- Replace unsupported layout or CSS with a print-oriented template.
- Embed or make fonts and images reachable from the conversion host.
- Capture the exact state you need instead of assuming a URL alone represents a logged-in or personalized view.
Alternative Java renderers and PDF libraries
| Option | What is established | Best decision question |
|---|---|---|
| iText pdfHTML | Accepts HTML as a String, file, or InputStream; the documented URL recipe uses URL.openStream(). pdfHTML is offered under AGPL/commercial terms. |
Do its HTML/CSS capabilities and license fit your deployment? |
| OpenHTMLtoPDF | Pure Java; supports a reasonable subset of well-formed XML/XHTML and some HTML5, with CSS 2.1-era support; LGPL 2.1 or later. | Can you author or adapt the page to its supported subset? |
| Flying Saucer | Pure Java renderer for well-formed XML/XHTML and CSS 2.1 with PDF output; LGPL. | Is XHTML-oriented layout sufficient, and is the maintained version suitable? |
| Apache PDFBox | Apache License 2.0 library for PDF creation, manipulation, and text extraction. | Do you need low-level PDF operations rather than turnkey HTML rendering? |
PDFBox is not established by the cited project description as an HTML-to-PDF renderer by itself. You would have to create the PDF content or pair it with a separate HTML renderer.
Licensing: check before shipping
OpenHTMLtoPDF states that it is distributed under LGPL version 2.1 or later. iText describes pdfHTML as dual licensed under AGPL and commercial terms; its installation guidance says commercial use requires a commercial license for iText Core and pdfHTML. Whether your application, hosted service, modification, linking model, or distribution triggers a particular obligation is a legal question these summaries cannot decide.
- Read the license text for the exact library version you deploy.
- Record whether you distribute the application, offer it as a service, or modify and redistribute components.
- Obtain a legal review for proprietary or revenue-generating deployments before selecting an AGPL option.
Production checklist for URL conversion
- Confirm reachability: fetch the URL from the same machine, container, or network segment that runs Java.
- Inspect the source: determine whether useful content is present in the initial HTML or appears only after JavaScript.
- Check assets: test every stylesheet, image, and font URL, including relative paths and redirects.
- Set a base URI: configure
ConverterProperties.setBaseUriwhen relative resources need it. - Control timeouts externally:
URL.openStream()is a simple stream API; use an HTTP client with explicit connect/read limits when you need operational timeout and retry policy, then pass the response stream to the converter. - Validate output: compare page count, text, images, fonts, margins, and page breaks against representative inputs.
- Isolate untrusted URLs: fetching arbitrary addresses can expose internal network resources. Apply your application’s allowlist, egress controls, and credential policy.
Or skip the browser setup
If your real requirement is a clean screenshot or PDF of a public page rather than a Java renderer embedded in your service, ScreenshotNeo provides a one-request API. It accepts consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in 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.
For an image or PDF endpoint, see the ScreenshotNeo documentation. The following cURL request saves a WebP screenshot:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request from 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)
And 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 PDF paper size, margins, landscape mode, and page ranges; full-page captures with lazy images loaded; CSS-selector element capture; device presets and custom viewports; dark mode, retina scale, custom CSS and JavaScript, clicks, waits, blocked requests, custom headers and cookies, timezone and geolocation, transparent backgrounds, resizing, chosen-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs, which can simplify migration.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errors| Plan | Included shots | Price |
|---|---|---|
| Free | 1,000 per month | No card required |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
Yearly billing provides two months free, and every feature is available on every plan. Start with 1,000 free screenshots a month—no card required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting common failures
Connection refused, timeout, or unknown host
The conversion machine cannot reach the URL or its DNS/proxy path. Test from that host, verify outbound HTTPS policy, and use an HTTP client with explicit timeouts. Do not assume a URL reachable in your desktop browser is reachable from a server.
Rank #4
PDF is blank or has only a shell
The useful content may be injected after JavaScript, blocked by a bot check, or unavailable without authentication. Inspect the initial response and provide server-rendered HTML or an authenticated, controlled fetch path.
Images or CSS are missing
Check relative URLs, redirects, TLS certificates, response permissions, and the configured base URI. Ensure the conversion process can access every asset and that the formats are supported by the chosen renderer.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Layout differs from the browser
Check unsupported CSS, malformed HTML, missing fonts, and JavaScript-dependent layout. Simplify or adapt the document for XHTML/CSS support, or choose a capture workflow whose rendering requirements match your target.
Best Value
License review blocks release
Pause deployment and compare the applicable AGPL, LGPL, Apache, and commercial terms with your distribution model. A library’s label alone is not a legal determination for your application.
Choosing a path
- Choose iText pdfHTML when you want the documented Java API, can make the content reachable, and its AGPL/commercial terms fit.
- Choose OpenHTMLtoPDF or Flying Saucer when your documents are controlled XHTML/CSS and LGPL licensing is appropriate.
- Use PDFBox for PDF manipulation or programmatic PDF construction, not as the sole HTML renderer based on the cited documentation.
- Use a browser-style capture service when the deliverable depends on dynamic page state, consent cleanup, or screenshot/PDF capture rather than a Java HTML layout engine.
Frequently Asked Questions
Does URL.openStream execute JavaScript?
It retrieves the URL response as a stream. It does not by itself establish browser-style JavaScript execution, interaction, or a fully rendered client-side state.
Can I use an authenticated URL?
The basic example does not show authentication. Implement a controlled HTTP fetch that supplies the credentials your application is allowed to use, then pass the resulting HTML stream to the converter.
Which renderer gives pixel-perfect Chrome output?
The cited material does not establish a browser-fidelity winner. Test representative pages, dynamic states, fonts, and assets with the renderer and version you plan to deploy.
Is this legal advice about AGPL or LGPL?
No. The article identifies the published licensing descriptions; have counsel assess your application’s distribution and service model.
Quick Recap
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.

