Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsSome links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
If an iText PDF looks unstyled while the same HTML looks correct in a browser, the usual cause is not one broken declaration. It is usually the converter, an incorrect base URI, an unsupported CSS feature, an unregistered font, the wrong media mode, or markup that JavaScript would have created in a browser. For complete documents, use iText 7 pdfHTML with HtmlConverter, configure the HTML base directory and fonts, select print media when needed, and pre-render JavaScript-driven content.
Find the failure before changing the stylesheet
Start with the smallest reproducible HTML file and classify the symptom. This prevents a font problem from being mistaken for a CSS-parser problem, or a missing image from being blamed on layout.
| What you see | Most likely cause | First check |
|---|---|---|
| All styling is absent | Legacy HTMLWorker, XML Worker, or an iText Core-only dependency |
Switch to the pdfHTML add-on and HtmlConverter. |
| Inline styles work, but linked CSS, images, or fonts do not | No base URI, or a base URI that points to the wrong directory | Set ConverterProperties.setBaseUri(...) to the directory containing the HTML and its relative resources. |
| Simple colors work, but shadows, filters, stacking, or custom properties do not | The declaration is outside pdfHTML’s supported or fully supported CSS subset | Check the support matrix for the exact pdfHTML version and replace the declaration with a supported equivalent. |
| Text uses a fallback typeface | The font file was not registered, the CSS family name does not match, or embedding is not permitted | Add the TTF/OTF to a font provider and verify its family name and embedding rights. |
| Browser print layout is missing | The converter is using screen media | Set a MediaDeviceDescription with MediaType.PRINT. |
| Content that appears after page load is absent | JavaScript inserted it, but pdfHTML does not execute JavaScript | Render the page with a browser engine first, then convert the resulting HTML. |
Use pdfHTML instead of the legacy converter
iText describes HTMLWorker as a tool for small, simple snippets. It did not parse CSS files and was removed from recent versions. XML Worker is also a legacy path, not the solution for a complete HTML/CSS document. The supported iText 7 approach is the separate pdfHTML add-on, which parses HTML and CSS and maps them to iText objects and styles.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Make sure the dependency you deploy is pdfHTML and that its version matches the iText Core version. Having iText Core alone is not equivalent to having the HTML/CSS converter. Remove old XML Worker code rather than trying to make it understand modern styles.
#1 Best Overall
A complete Java configuration
The following pattern establishes the three settings that solve the most common resource and print issues: a base URI, an explicit font provider, and print media. The API names and constructor overloads can vary between pdfHTML releases, so use the signatures supplied by the version in your build.
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.css.media.MediaDeviceDescription;
import com.itextpdf.html2pdf.css.media.MediaType;
import com.itextpdf.layout.font.DefaultFontProvider;
import com.itextpdf.layout.font.FontProvider;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class HtmlToPdf {
public static void main(String[] args) throws Exception {
ConverterProperties props = new ConverterProperties()
.setBaseUri("/app/templates/invoice/");
FontProvider fonts = new DefaultFontProvider(false, false, false);
fonts.addFont("/app/fonts/Inter-Regular.ttf");
props.setFontProvider(fonts);
props.setMediaDeviceDescription(
new MediaDeviceDescription(MediaType.PRINT));
HtmlConverter.convertToPdf(
new FileInputStream("/app/templates/invoice/index.html"),
new FileOutputStream("invoice.pdf"),
props);
}
}
Here, index.html can refer to css/invoice.css, images/logo.svg, and a relative font URL. The base URI must be the directory from which those relative paths are resolved, not merely the directory in which your Java class happens to run.
Confirm the base URI with an absolute-path test
When diagnosing a failure, temporarily replace a relative stylesheet or image URL with an absolute file path or a directly resolvable URL. If the resource then appears, the CSS itself is probably not the issue; correct the base URI and restore relative references. Keep the base URI stable in production so templates behave the same regardless of the process working directory.
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 minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Resolve stylesheets, images, and other relative resources
Browsers resolve href and src relative to the document URL. A Java process reading a file stream does not automatically provide that URL context. setBaseUri supplies it to pdfHTML. The same rule applies to:
<link rel="stylesheet" href="...">files;- background images in CSS;
- image, SVG, and other media references in HTML;
- font URLs declared in CSS.
Check spelling and case as well as directory depth; a path that works on a case-insensitive development machine can fail on a case-sensitive server. During isolation, reduce the document to one stylesheet, one image, and one font so that a single bad URL cannot hide the successful resources.
Design for pdfHTML’s CSS support matrix
pdfHTML supports a substantial portion of HTML and CSS, but it is not a browser layout engine. Browser compatibility therefore does not prove PDF compatibility. The current support matrix is based on pdfHTML 6.3.3 released with iText Core 9.7.0; support can change in later releases, so compare your declarations with the matrix for the exact version you run.
Rank #3
| Feature reported as unsupported or limited | Practical response |
|---|---|
box-shadow |
Use a border, background, or a pre-rendered graphic when a shadow is essential. |
filter |
Apply the visual effect before conversion or remove it from the print stylesheet. |
z-index |
Reorder elements in the HTML and use simpler positioning. |
overflow |
Let content flow, set explicit dimensions carefully, or split the content into printable sections. |
| CSS custom properties | Replace variables with concrete values in the conversion stylesheet. |
writing-mode |
Use a supported layout or create the specialized text as an image/PDF fragment. |
Do not remove a whole stylesheet because one advanced declaration fails. Reduce the CSS to a visible property such as color, font-size, background-color, or border. Once that renders, add declarations back in small groups and compare each failing declaration with the support matrix.
Make custom fonts render and embed correctly
A browser can use a locally installed font or download one through its own resource pipeline. A server-side conversion needs the font file available to the configured provider. Create a DefaultFontProvider, add each required TTF or OTF with addFont, and attach it to ConverterProperties, as shown in the Java example.
- Use the family name that the font declares, not necessarily the filename. The CSS
font-familymust match that name. - Register every weight and style that the document requests if you need predictable bold and italic output.
- Check that the font’s license permits embedding in a PDF. A technically correct configuration cannot override embedding restrictions.
- Test a short paragraph containing distinctive glyphs. A fallback can look acceptable for basic Latin text while failing for symbols or non-Latin scripts.
If the font still falls back, verify the file path independently, inspect the CSS family spelling, and temporarily remove other family names from the stack so the selected face is unambiguous.
Rank #4
- Used Book in Good Condition
Tell pdfHTML to use print styles
Rules inside @media print are not automatically selected just because the output format is PDF. Set MediaDeviceDescription(MediaType.PRINT) on the converter properties. Without that setting, print-only declarations such as page-specific spacing, hidden navigation, or print colors may not participate in layout.
Keep screen and print concerns separate where possible. A compact print stylesheet that uses supported properties is easier to diagnose than a browser stylesheet containing animation, interaction states, and screen-only overlays.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Pre-render JavaScript-generated HTML
pdfHTML parses the HTML and CSS it receives; it does not execute JavaScript. If a framework inserts invoice rows, applies a class, or fetches data after load, that markup is not present for conversion. Render the page first with a browser engine such as headless Chrome, wait for the application to finish, save the resulting HTML (or otherwise capture the generated content), and pass that stable output to pdfHTML.
Best Value
- Used Book in Good Condition
Do not treat adding a longer conversion delay as a JavaScript solution. A delay in Java code cannot execute scripts that pdfHTML does not implement. The reliable boundary is browser rendering first, PDF conversion second.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Handle custom elements and custom CSS behavior
Ordinary supported HTML tags are the best diagnostic baseline. If a custom element renders as empty or loses its styling while a normal div with the same declarations works, the problem may be the element-to-layout mapping rather than CSS syntax.
pdfHTML exposes extension points for this case. Register a custom tag worker through the relevant DefaultTagWorkerFactory mechanism, and register a CSS applier through DefaultCssApplierFactory when the element needs special styling behavior. Add these extensions through ConverterProperties. First simplify the custom component to a supported HTML structure; extend only the mapping that cannot be represented with standard tags.
Free tools Windows power users keep installed
One-click scans. No signup required.
A repeatable troubleshooting procedure
- Verify the converter. Confirm that the application includes pdfHTML, not only iText Core or a legacy XML Worker artifact.
- Freeze the input. Save the exact HTML that the converter receives. If it depends on JavaScript, produce the browser-rendered version first.
- Prove resource resolution. Set the correct base directory and test one stylesheet, one image, and one font with known paths.
- Prove basic CSS. Replace the failing rule with
color,font-size,background-color, orborder. If that works, investigate feature support rather than file loading. - Check selectors. Apply the rule to an ordinary supported tag. If it works there but not on a custom element, inspect tag-worker registration.
- Check media. Select print media when the intended declarations are inside
@media print. - Check fonts. Confirm file access, family names, requested weights, and embedding permissions.
- Compare the support matrix. Review every declaration that still differs from the browser result against the matrix for your installed version.
Reliability, performance, and operational considerations
- Keep templates deterministic. A fixed base directory, explicit fonts, and a saved browser-rendered input make failures reproducible across machines.
- Separate browser work from conversion work. Browser rendering handles JavaScript; pdfHTML handles the supported HTML/CSS-to-PDF mapping. Logging which stage failed shortens incident diagnosis.
- Prefer small conversion fixtures. A one-page document with one suspect rule reveals parser and resource problems faster than a full production invoice.
- Pin and validate versions. The support matrix is version-specific. Recheck styles when upgrading pdfHTML or iText Core, and validate against the Java or .NET runtime used in deployment.
- Plan for licensing and support. pdfHTML is an iText add-on used in production deployments; review the licensing terms and available implementation support for your distribution model before rollout.
Or skip the browser setup
If your real goal is a clean screenshot or PDF of a live, JavaScript-driven website rather than an iText-generated document, ScreenshotNeo handles the browser capture in one request. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. It also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
For API options and parameter details, see the ScreenshotNeo documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
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 returns PNG, JPEG, WebP, or PDF and includes options such as full-page capture with lazy images loaded, CSS-selector element capture, device and retina settings, custom CSS and JavaScript, waits, request blocking, authentication headers and cookies, geolocation, signed links, asynchronous webhooks, bulk capture, caching, and usage reporting. One thousand screenshots each month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
The Bottom Line
For missing styles in an iText PDF, use pdfHTML, set a correct base URI, register fonts, select print media, stay within the supported CSS matrix, and pre-render any JavaScript-driven content before conversion.
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.

