Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
For new Java applications, convert HTML and CSS with iText’s pdfHTML add-on and its HtmlConverter API. Add the Maven artifact com.itextpdf:html2pdf, use a release compatible with your iText Core version, and decide whether the project can operate under AGPL or needs a commercial license before deployment.
The current iText approach
pdfHTML is iText Core’s add-on for Java and .NET that converts HTML and CSS into PDF. The primary entry point is HtmlConverter; it accepts an HTML file, stream or string and writes a PDF file or stream. iText describes pdfHTML as producing PDFs that are “accessible, searchable and usable for indexing,” but the exact HTML, CSS, font and standards support depends on the pdfHTML release.
What you need
- A Java project with iText Core and the pdfHTML add-on.
- An
html2pdfversion compatible with the Core version you license. - Readable HTML, reachable images and fonts, and enough temporary storage for the conversion.
- A licensing decision covering development, deployment and distribution.
Add pdfHTML to Maven
The installation artifact is com.itextpdf:html2pdf, available from Maven Central and iText’s Artifactory. Do not copy a “latest” version into production: release numbers change, and pdfHTML must match the iText Core line in your project. Use iText’s compatibility matrix when selecting both versions.
Recommended Free Tools
<properties>
<itext.version>YOUR_COMPATIBLE_VERSION</itext.version>
</properties>
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-core</artifactId>
<version>${itext.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>${itext.version}</version>
</dependency>
</dependencies>
Keep Core and html2pdf on the same compatible release family. If your organization uses an iText BOM or approved dependency-management file, use that instead of duplicating versions. After changing versions, run your complete PDF and accessibility test suite; a project that compiles can still render a changed subset of CSS differently.
A complete Java conversion
This example follows the documented stream-based pattern. It closes both streams automatically and writes output.pdf from input.html.
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public final class HtmlToPdf {
public static void main(String[] args) throws Exception {
ConverterProperties properties = new ConverterProperties();
try (InputStream html = new FileInputStream("input.html");
OutputStream pdf = new FileOutputStream("output.pdf")) {
HtmlConverter.convertToPdf(html, pdf, properties);
}
}
}
Compile and run it with the dependency classpath supplied by Maven. The converter reads the HTML stream and emits a PDF stream; it does not require a browser process. In production, catch and log conversion exceptions, validate input paths, and write to a temporary file before atomically moving the finished PDF into place.
Converting a string or returning bytes
For templates held in memory, use the overload that accepts a string or character stream. For an HTTP response, write to a ByteArrayOutputStream, then send its byte array with Content-Type: application/pdf and a suitable download disposition. Keep untrusted HTML isolated and enforce limits on input size, embedded resources and conversion time.
Resolving relative images, CSS and fonts
HTML commonly contains relative URLs such as css/site.css or images/logo.svg. Configure a base URI with ConverterProperties so those references resolve from the intended directory or URL. For controlled deployments, package assets locally and allow only approved schemes and directories. Register fonts explicitly when the template depends on a font that is not available in the runtime image; otherwise text may fall back to another font or fail to render as expected.
License choice before shipping
iText’s open-source downloads use the AGPL. iText’s installation guidance directs non-commercial users to agree to that license, while commercial use requires a commercial license for both iText Core and pdfHTML. This is vendor guidance, not legal advice. Review the actual license terms with counsel for your application, SaaS deployment, redistribution model and obligations to provide corresponding source where applicable.
Rank #2
- AGPL route: suitable only when your project and distribution can comply with AGPL obligations.
- Commercial route: obtain commercial licensing for Core and pdfHTML when your use or distribution is not compatible with AGPL.
- Operational check: record the exact licensed Core and pdfHTML versions used in each build.
Why not HTMLWorker or XML Worker?
Do not start a new implementation with HTMLWorker. iText says the class was deprecated many years ago and removed in recent versions; it was intended for simple snippets and did not provide full tag and CSS support. XML Worker belongs to the older iText 5 ecosystem and expects predictable XHTML-oriented content. It is not a modern URL-to-PDF renderer.
If you are migrating, replace the old parser with pdfHTML, then compare representative documents: headings, tables, lists, page breaks, images, web fonts, right-to-left text and generated links. Keep the old and new outputs available during a controlled transition, but do not assume pixel-for-pixel equivalence.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteHTML and CSS support: set realistic expectations
pdfHTML is not a full browser engine. Supported elements and CSS vary by release, and browser-only behavior, JavaScript-driven layout and unsupported CSS can produce a different PDF. Check the support matrix for your exact version before promising a template feature.
| Requirement | What to do |
|---|---|
| HTML tags and CSS properties | Check the version-specific supported/unsupported matrix and test a real template. |
| Fonts and glyph coverage | Package and register the required fonts; verify non-Latin text and fallback behavior. |
| Images and external resources | Provide a base URI or controlled absolute resources; test permissions and timeouts. |
| Page breaks and long tables | Use supported print CSS and inspect multi-page output at the target paper size. |
| PDF/A or PDF/UA | Use the version’s conformance features, then validate the generated document independently. |
The surfaced feature information is scoped to pdfHTML 6.3.3 with iText Core 9.7.0. It reports PDF/UA-1, PDF/UA-2 and PDF/A-family support. Those are advertised implementation capabilities, not proof that every generated file conforms. Validate archival and accessibility requirements with an appropriate validator.
Version note: pdfHTML 6.3.3
iText records pdfHTML 6.3.3 as released July 8, 2026. That release added support for the CSS :is(), :where() and :not() pseudo-classes, improved tolerance of malformed CSS, and addressed CSS Grid pagination and list-rendering performance bugs. Treat these as release-note changes, not a guarantee for later versions or for every stylesheet. Pin and test the version you deploy.
Production workflow
- Normalize the template. Make the document self-contained where possible, use valid HTML, and remove browser-only JavaScript dependencies.
- Select compatible dependencies. Align html2pdf with the licensed iText Core version and record the choice in dependency management.
- Configure resources. Set a base URI, register fonts and restrict external access to approved locations.
- Convert with bounded resources. Apply request size, memory, temporary-storage and execution-time limits around the conversion.
- Validate output. Check that the file opens, pages have the expected size and orientation, links work, fonts are embedded as required, and accessibility or archival validators pass when applicable.
- Observe failures. Log the template identifier, library versions and exception category without logging sensitive document contents.
Troubleshooting
Dependency conflicts or missing classes
Cause: html2pdf and Core are from incompatible release lines, or transitive dependencies were overridden. Fix: inspect the Maven dependency tree, remove duplicate iText versions, and select a pair from the compatibility matrix.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Images or styles are missing
Cause: relative URLs have no base URI, the process cannot read the resource, or the URL scheme is blocked. Fix: package assets locally or configure the correct base URI, then test file permissions and network policy.
Unexpected fonts, squares or missing characters
Cause: the required font is absent, not registered, or lacks the glyphs. Fix: register a font with the converter configuration, include the correct font files, and test scripts such as Arabic, CJK or emoji separately.
Layout differs from the browser
Cause: browser JavaScript, unsupported CSS, different font metrics or print pagination. Fix: consult the support matrix, simplify unsupported rules, provide print-oriented CSS, and compare a fixed test fixture after every library upgrade.
Conversion is slow or memory-heavy
Cause: very large DOMs, high-resolution images, many embedded fonts or complex tables. Fix: resize source images, split exceptionally large documents, limit concurrent conversions and profile representative templates. No general speed benchmark is established here, so measure with your own documents and deployment limits.
Rank #4
PDF/A or PDF/UA validation fails
Cause: conformance requires document metadata, tagging, fonts, color handling and structure beyond merely creating a PDF. Fix: configure the relevant standard deliberately, inspect validator findings and correct the source template and conversion settings before release.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your actual requirement is a screenshot or PDF capture of a live webpage rather than rendering your own HTML template, ScreenshotNeo provides a single HTTP call and an MCP server for AI clients. It accepts cookie and consent banners like a visitor, removes more than 60 known consent platforms plus newsletter popups and chat widgets, and lets you turn each cleanup step off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed; the response identifies the page verdict and billing status in headers.
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 documentation for PDF options, CSS selectors, waiting rules, authentication headers, cookies, device presets and signed webhooks. The same service supports full-page capture, element selection, dark mode, retina scale, custom JavaScript and CSS, request blocking, geolocation, transparent backgrounds, resizing, caching, bulk capture and asynchronous jobs. Its MCP tools are take_screenshot, get_page_info and capture_pdf, so Claude, Cursor and other MCP clients can capture pages without your maintaining a browser stack.
Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
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}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
require('fs').writeFileSync('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo’s Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to try it without a card.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Frequently asked questions
Can pdfHTML convert a remote webpage URL directly?
Use a controlled HTML input and resource configuration for predictable server-side conversion. A live page that depends on browser JavaScript, consent interactions or bot checks is a different capture problem; use a browser-capable capture service instead.
Should I upgrade just pdfHTML?
No. Plan Core and pdfHTML as a compatible pair, review the release notes, and run regression fixtures before upgrading either component.
Best Value
Does creating a PDF prove it is accessible?
No. Accessibility depends on document structure and metadata as well as conversion support. Run an independent PDF/UA check on the files you ship.
Frequently Asked Questions
Can pdfHTML convert a remote webpage URL directly?
Use controlled HTML input and resource configuration for predictable server-side conversion. Live pages that rely on browser JavaScript or consent interactions require a browser-capable capture approach.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallShould I upgrade only pdfHTML?
Treat iText Core and pdfHTML as a compatible pair, review release notes, and run regression fixtures before upgrading.
Does creating a PDF prove accessibility?
No. Validate the generated document independently for PDF/UA and your organization’s accessibility requirements.
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.

