Recommended Free Tools
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 a current Java project, use iText pdfHTML with iText Core and convert through the HtmlConverter API. The short string-based example is straightforward; real XHTML files also need correct relative-resource handling and a check against pdfHTML’s versioned HTML and CSS support. iText identifies pdfHTML as its current HTML/XML conversion add-on and XML Worker as the older iText 5 route. iText’s product overview explains that distinction.
Use pdfHTML for current iText projects
pdfHTML is iText’s add-on for converting HTML or XML and associated CSS into PDF with iText Core. Its high-level Java entry point is HtmlConverter. For new work, use that API rather than starting with HTMLWorker or XML Worker, which belong to older iText generations. The distinction matters: migration from old code involves dependencies, supported markup, and licensing—not just changing a class name.
The official tutorial’s minimal example converts an HTML string directly to a file:
HtmlConverter.convertToPdf(html, new FileOutputStream(dest));
This demonstrates the basic call, not a guarantee that every complete XHTML document or browser-oriented CSS feature will render as expected. For a production document, first establish how the converter will find linked resources, then compare the markup and styling you rely on with the support matrix.
Add the Java dependency and check versions
Add com.itextpdf:html2pdf to your build. The exact version and dependency setup should follow iText’s current Java installation guidance; in particular, confirm that the pdfHTML and iText Core versions you select are compatible with one another and covered by your intended license. See iText’s pdfHTML installation guide before pinning versions.
At the time of this article, iText’s feature reference uses pdfHTML 6.3.3 with iText Core 9.7.0 as its support baseline. pdfHTML 6.3.3 was released July 8, 2026. These are version-specific reference points, not a reason to assume they are the right versions for every application: verify compatibility and licensing against the versions you actually deploy.
For Maven, the dependency has this artifact coordinate; choose a version that matches your project and the current installation guidance:
Windows 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 reinstallCrashes, 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 minute<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>YOUR_COMPATIBLE_VERSION</version>
</dependency>
Replace the version token with a real version before building. The appropriate Core dependency and any license-key library depend on your chosen release and use case, so do not copy a dependency set from an unrelated iText version without checking the official guide.
Rank #2
Convert an XHTML file, including relative resources
A file may refer to stylesheets, images, or other resources through relative paths. A conversion that receives only the markup text cannot infer the intended directory unless you provide an appropriate base URI or use a file/stream overload whose resource behavior suits the document. iText documents multiple input forms; consult the API documentation for the exact overload and configuration for your deployed version. The central requirement is that resource references resolve from the same intended location they use in the source document.
- Prepare the document. Ensure it is well-formed XHTML and identify its linked CSS, images, fonts, and other external assets.
- Choose the input form. Use the documented
HtmlConverteroverload for a file, stream, or string. For a string or stream with relative links, configure a base URI through the applicable converter configuration. - Write to a destination. Use a file or output stream that your application can create and close reliably.
- Inspect the result. Open the produced PDF and check page breaks, images, fonts, styling, and any required PDF conformance.
- Validate the deployed version. Compare each important element and CSS feature with the support matrix for the pdfHTML/Core version in your build.
The minimal official Java example is a useful starting point when html is already available as a string:
import com.itextpdf.html2pdf.HtmlConverter;
import java.io.FileOutputStream;
import java.io.IOException;
public class HtmlToPdf {
public static void main(String[] args) throws IOException {
String html = "<html><body><h1>Hello</h1></body></html>";
String dest = "output.pdf";
try (FileOutputStream output = new FileOutputStream(dest)) {
HtmlConverter.convertToPdf(html, output);
}
}
}
This example is intentionally limited to self-contained markup. For a real XHTML file, use the file or stream approach and resource configuration documented for your version rather than assuming relative references will resolve from the process’s working directory. The tutorial’s API example and input discussion are in iText’s “Hello HTML to PDF” chapter.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Check XHTML, CSS, and PDF requirements before relying on output
The fact that a source is labeled XHTML does not establish that every tag, CSS declaration, or browser-specific behavior is supported. Use iText’s versioned pdfHTML support matrix to check the features your document needs. The reference changes over time and identifies its baseline; read the matrix for the versions in your application.
pdfHTML 6.3.3 release notes report support for CSS :is(), :where(), and :not() pseudo-class selectors, improved tolerance for malformed CSS, and fixes involving CSS Grid pagination and list-rendering performance. Those are specific release notes, not a promise of complete CSS compatibility or browser-identical layout. Render representative documents and inspect the PDF whenever layout fidelity matters.
- External files: verify that stylesheets and images resolve from the configured base location.
- Layout: inspect page breaks, overflowing content, lists, and grid-based sections.
- Fonts and images: check that the output contains the expected assets and appearance.
- Conformance: if a particular PDF standard is required, verify it explicitly; the XHTML input label alone does not establish conformance.
For the release-specific changes and date, see iText’s pdfHTML 6.3.3 release note.
Choose a license that fits how you distribute the application
iText’s licensing guidance says noncommercial use requires agreement to the AGPL. For closed-source commercial use, iText says a commercial license is required for both iText Core and pdfHTML. Its installation guide also describes adding the license-key library for commercial use. Review the terms for your distribution and obtain the appropriate license before shipping; do not assume that the code being free to download makes every deployment permitted.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteLicensing applies to the relevant iText components, not just the HTML conversion call. Use the official installation and licensing guidance to check the setup for your selected versions.
Rank #4
Why old iText examples may not work
Many older tutorials show HTMLWorker or XML Worker. iText describes XML Worker as the iText 5-era option; iText 5 is end of life, and pdfHTML is the current route for iText Core. HTMLWorker was deprecated and removed in recent iText versions, and it was intended for simple snippets rather than full pages with CSS. See iText’s conversion history and guidance.
If maintaining an iText 5 application, treat the change as a migration: review your dependencies, adapt the conversion flow to pdfHTML, check markup and CSS against current support, and verify the license. Replacing an old class name alone does not establish that the new code, resources, or output will behave equivalently.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common conversion problems
- Styles or images are missing: relative references may not have a usable base location. Use the appropriate file/stream overload or configure a base URI, then verify paths and access permissions.
- The PDF looks different from a browser: check the exact CSS and element support for your deployed version. A successful conversion does not imply browser-equivalent rendering; adjust unsupported styling or use supported alternatives, then inspect again.
- Old imports or examples fail to compile: the example may use HTMLWorker or XML Worker APIs from an earlier iText generation. Use the pdfHTML API for current iText Core work and consult the migration-relevant documentation.
- Dependency resolution or compatibility errors occur: check the
html2pdfversion, matching Core version, and installation instructions together rather than mixing artifacts from different release generations. - Commercial deployment is blocked by license setup: verify the required license for both Core and pdfHTML and whether your setup needs the license-key library.
- A required layout feature is absent or unstable: check the versioned support matrix and release notes, then test a representative document with the exact deployed versions before relying on it.
Or skip the browser setup
If your goal is to capture a web page as a PDF rather than convert an XHTML file with iText, ScreenshotNeo offers a one-request screenshot API and MCP server. A request can return a PDF as well as PNG, JPEG, or WebP. It is a different workflow from embedding XHTML conversion in a Java application.
Free tools Windows power users keep installed
One-click scans. No signup required.
For API setup and available request options, see the ScreenshotNeo documentation. One cURL request captures a URL:
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response indicates the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.
The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for the free plan to try it without a card.
FAQ
Does pdfHTML convert XHTML as well as HTML?
iText describes pdfHTML as supporting HTML/XML and associated CSS. Check the feature matrix for the exact elements and styling your XHTML uses.
Can I expect the PDF to look exactly like Chrome?
No browser-equivalence guarantee is established here. Confirm your required markup and CSS against the versioned feature matrix and inspect the generated PDF.
Is XML Worker the current choice?
No. It is associated with iText 5, which iText identifies as end of life; pdfHTML is the current add-on for iText Core.
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.

