What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

If CSS is missing from an iTextSharp-generated PDF, first confirm the application is using XMLWorker rather than HTMLWorker, then make the HTML well-formed XHTML and explicitly pass any external stylesheet to the XMLWorker pipeline. If those checks pass, reduce the problem to one element and one rule: XMLWorker supports CSS, but that does not mean it implements every browser CSS feature.

Start by checking which HTML parser creates the PDF

iTextSharp and its HTML-to-PDF components are sometimes described as if they were one parser, but the distinction matters. The iText troubleshooting guidance says HTMLWorker does not support CSS; XMLWorker is the separate component intended to process CSS. A project can reference iTextSharp and still be calling HTMLWorker.

  1. Search the code path that creates the PDF for HTMLWorker, XMLWorkerHelper, or XMLWorker pipeline classes.
  2. Confirm the production path—not just a test or a different project—calls XMLWorker.
  3. Check that the XMLWorker component is included alongside the iTextSharp assembly. It is a separate component, not simply a CSS switch inside the core DLL.
  4. Record the installed iTextSharp and XMLWorker package or DLL versions before changing code. Verify any method overload against those exact assemblies.

If the code calls HTMLWorker, switch to the XMLWorker path before debugging individual CSS declarations. A change to the stylesheet cannot make a parser without CSS support apply those rules.

Make the HTML valid and consistent before adjusting CSS

Browsers often recover from malformed markup and still display a page. That does not establish that XMLWorker will interpret the same input the same way. The official iText troubleshooting article identifies invalid HTML as a cause of unexpected conversion and describes correcting both structure and CSS before the output rendered as expected.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Check the exact HTML string or file passed to the converter, not only the original template. In particular, look for unclosed or incorrectly nested elements, inconsistent table structure, invalid attribute syntax, and markup that changes between the browser preview and the PDF request. Repair the document structure first, then test the styling again.

  • Make the input well-formed XHTML: close elements, nest them consistently, and use valid attribute syntax.
  • Check generated content after template expansion. A valid template can produce invalid output when inserted text or conditional fragments alter the markup.
  • Use a minimal document containing the affected element and its necessary parent structure to separate markup problems from stylesheet problems.
  • Do not treat a successful browser render as validation of XMLWorker input. Browser error recovery and XMLWorker parsing are not interchangeable guarantees.

Pass external CSS to XMLWorker explicitly

A stylesheet sitting beside an HTML file—or linked in a browser-facing page—is not proof that it reaches XMLWorker. The application must open the intended CSS content and supply it through a supported XMLWorker API. The iText example documents two approaches: a parseXHtml overload that accepts HTML and CSS input streams, and a custom pipeline that attaches a parsed CssFile to a CSSResolver.

Use the HTML-and-CSS stream overload when it fits

For a straightforward conversion, use the version-matched parseXHtml overload that accepts both the HTML input stream and CSS input stream. Confirm the overload exists in the XMLWorker DLL actually deployed. Supply streams containing the intended bytes, with an encoding consistent with the document and stylesheet; do not assume that a file path, a browser link, or a default encoding will be resolved as desired.

Use a resolver pipeline when you need explicit control

The documented custom-pipeline pattern is to create a CSSResolver, parse the stylesheet input into a CssFile, add that file to the resolver, connect the resolver to a CssResolverPipeline, and connect that pipeline to the HTML and PDF-writer pipelines before parsing. The Knowledge Base example is Java-oriented, so translate types and method casing only after checking the C# API exposed by your installed XMLWorker version.

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

There is no safe version-independent C# listing to paste without knowing the exact XMLWorker DLL: overloads, helper methods, stream handling, and pipeline APIs need to match the referenced release. Avoid copying a Java sample as though it were C#, or inserting guessed calls such as a presumed stylesheet-loading helper. Use the documented API surface for the package in the application, then verify that the CSS bytes arrive at the resolver.

Verify the stylesheet that actually reaches the converter

  • Log or inspect the resolved file path and confirm the application account can read it.
  • Check the stream is non-null, non-empty, and contains the expected rules rather than an outdated or empty file.
  • Confirm the stylesheet is passed into the conversion flow, not merely referenced by an href that works in a browser.
  • Check character encoding if selectors, content, or values include non-ASCII characters.
  • Make a temporary change to one simple declaration and confirm the PDF reflects it. Revert the test after verifying which file is in use.

Isolate the CSS rule that fails

Once the parser is XMLWorker, the markup is valid, and the CSS input is demonstrably supplied, test the smallest failing case. Keep one element, one selector, and one declaration; then add the original document structure and other rules back in stages. This reveals whether the issue is stylesheet loading, selector matching, markup structure, or a rule that the installed XMLWorker does not handle as expected.

CSS support is not a promise of complete browser compatibility. The cited iText material does not provide a complete property-by-property compatibility matrix, so do not assume that a current browser layout technique or a particular CSS property works in every XMLWorker release. Check the documentation and behavior for the exact version in use. If a required rule remains unsupported or behaves differently, consider whether the design can be expressed using supported markup and rules, or whether the rendering component needs to change.

Use a browser screenshot only to compare the visual result

A browser screenshot can help capture the browser-rendered page for a side-by-side visual comparison with the PDF. It does not reveal which parser your .NET code called, prove that XMLWorker received a stylesheet, or make browser CSS behavior available in XMLWorker. Treat it as a visual reference—not a fix for PDF generation.

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

Or skip the browser setup

To capture a reference image of a public page with one request, use ScreenshotNeo. This is for the browser-side visual reference only; continue using the XMLWorker checks above to fix the PDF.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

ScreenshotNeo API documentation

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

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. 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 headers. Its MCP server gives AI agents screenshot, page-information, and PDF-capture tools. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

When a repair is not enough: account for XMLWorker’s legacy status

The iTextSharp project repository labels iTextSharp end-of-life and says it has been replaced by iText 7, with only security fixes to be added. That is a project-status statement, not proof that every existing application must migrate immediately. If the current application works and its requirements are met, weigh a targeted repair against the cost and risk of changing a production PDF pipeline.

For a new project, or when a required CSS behavior cannot be achieved with the installed XMLWorker, evaluate a maintained rendering option rather than building an increasingly custom legacy pipeline. The available material establishes neither a full CSS feature matrix nor migration effort, so estimate both against your actual templates, output requirements, dependencies, and test coverage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Keep and repair: appropriate when the issue is a wrong parser, missing CSS stream, or invalid input and the corrected output meets requirements.
  • Work around a rule: consider when a small markup or stylesheet change produces the required PDF without relying on uncertain browser-only behavior.
  • Evaluate migration: consider when a required feature remains unavailable, long-term maintenance matters, or the application’s support requirements no longer fit the legacy component.
  • Review licensing separately: for commercial use, check current iText terms for the actual deployment and distribution model. Do not infer present-day licensing obligations from old technical examples.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting by symptom

Symptom Likely check Next action
No CSS seems to apply The conversion path may call HTMLWorker, or XMLWorker may not be included. Confirm the parser and deployed component before editing the CSS.
Inline or some styles work, but linked styles do not The external stylesheet may not be opened or passed to XMLWorker. Verify the file path, stream contents, encoding, and chosen CSS-input overload or resolver configuration.
The PDF structure or selectors look inconsistent The input may be malformed or differ from the markup tested in a browser. Inspect the final generated HTML and repair it to well-formed XHTML.
One rule fails after other checks pass The rule may not behave as expected in this XMLWorker version. Reduce the document to one rule and verify that behavior against the installed version; do not assume browser support.
A sample does not compile The sample may target Java, a different iText release, or another overload. Match the sample to the C# API and assemblies actually referenced by the application.

Change one variable at a time and save a known-good PDF before changing the pipeline. That makes it easier to tell whether the repair fixed parsing, CSS loading, or a single rule—and gives you a rollback point if a production conversion regresses.

Frequently Asked Questions

Will fixing the stylesheet path make the PDF match Chrome exactly?

No. Supplying the stylesheet addresses whether XMLWorker receives CSS; it does not establish that XMLWorker implements every browser styling behavior.

Can I use the Java XMLWorker example directly in an iTextSharp project?

No. Treat it as a pipeline pattern and verify equivalent classes and overloads in the C# assemblies and versions your application uses.

Does a browser screenshot diagnose the XMLWorker parser?

No. It records the browser’s visual output. It cannot establish which parser your application called or which CSS data reached the PDF conversion.

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

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.