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 reinstallSome 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 iText 7 projects, add the iText pdfHTML module alongside iText Core, then convert the HTML with HtmlConverter.convertToPdf and a configured ConverterProperties. Android projects need iText’s Android-specific artifacts from its Android Maven repository; linked stylesheets, images, and fonts also need paths the converter can resolve. pdfHTML translates supported HTML and CSS into PDF layout—it does not reproduce every browser behavior.
Use pdfHTML for a new iText integration
pdfHTML is iText’s HTML-and-CSS-to-PDF add-on for iText 7. Its converter maps HTML elements to layout objects and CSS declarations to layout properties. The basic conversion call is short; most Android integration work is making sure the right artifacts, files, and fonts are available to it.
If your application still uses iText 5 XML Worker, that is a legacy alternative with narrower CSS and layout support. For a new iText 7 integration, use pdfHTML rather than starting with XML Worker.
Recommended Free Tools
Add the Android artifacts that match
Configure your Android project to use iText’s Android Maven repository and use the Android-specific artifact variants, whose module names use the -android suffix and whose current examples use the com.itextpdf.android coordinates. Include iText Core and the matching pdfHTML module. Keep all iText modules on the same supported release line; do not combine arbitrary versions or mix Android and non-Android variants without checking compatibility.
#1 Best Overall
The exact repository declaration and artifact version depend on the iText release line you select. Check iText’s current Android installation instructions before adding dependencies; the available reference material does not establish one universally applicable version number or repository declaration. The conversion code below assumes the compatible Core and pdfHTML artifacts are already in the app’s dependencies.
Convert HTML to a PDF stream
This Java method shows the essential conversion flow. It accepts HTML and a destination PDF stream so the caller can choose Android storage, a cache file, or another output destination. The streams remain owned by the caller and should be closed by the code that created them.
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.ConverterProperties;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public final class HtmlPdf {
private HtmlPdf() {}
public static void convert(InputStream htmlInput,
OutputStream pdfOutput) throws IOException {
ConverterProperties properties = new ConverterProperties();
HtmlConverter.convertToPdf(htmlInput, pdfOutput, properties);
}
}
For example, call convert with an HTML input stream and a FileOutputStream for a file in an app-accessible directory. This minimal form is appropriate when the document’s CSS and content are inline or do not depend on external resources. It is not enough to make relative asset URLs work automatically: configure a base URI for those.
Make external CSS, images, and fonts resolvable
HTML such as <link rel="stylesheet" href="styles.css"> contains a relative resource reference. pdfHTML needs a base URI or another resource-resolution arrangement that lets it locate the stylesheet. The same issue applies to image URLs and font files referenced by the document or CSS. For Android, place resources in storage or packaged assets that the app can access, then ensure the URI you provide actually points to them.
Rank #2
Set a base URI for app files
If the HTML refers to files relative to a directory, configure that directory as the base URI. Pass an Android-accessible directory path, not an assumed desktop path or a URL that the device cannot access.
ConverterProperties properties = new ConverterProperties();
properties.setBaseUri(filesDirectory);
HtmlConverter.convertToPdf(htmlInput, pdfOutput, properties);
Here, filesDirectory must be replaced in your application with the actual path or URI for the directory containing the referenced resources. Keep the document’s relative paths consistent with that directory. For packaged assets, arrange access through a resource-resolution strategy appropriate to the app; do not assume a normal filesystem path exists for every asset.
Register custom fonts when needed
When the PDF must use fonts beyond those available by default, provide a configured FontProvider through ConverterProperties.setFontProvider. Make sure the font files are accessible to the app and that the CSS names the intended family. A font can be present in the APK yet still fail to be used if the converter cannot resolve its location or the CSS family does not match.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →iText also exposes a MediaDeviceDescription configuration option for print-media rules. Use the print media configuration when the stylesheet has print-specific declarations and verify the result with the exact version and document structure used by the app.
Know what CSS support does—and does not—mean
pdfHTML converts supported CSS into PDF layout properties; it is not a full browser engine. A stylesheet that works in Chrome or Android WebView may not produce identical pagination, positioning, font metrics, or layout in the generated PDF. Support can vary by feature and pdfHTML release, so validate the output from the version you ship.
Test the constructs that materially affect your documents, especially page breaks, floats, fixed positioning, tables, fonts, and media rules. Also test long content and boundary cases: a page that looks correct in a short sample can paginate differently when text wraps or an image changes the available space. Treat the generated PDF as the output to inspect, rather than assuming browser rendering guarantees a matching PDF.
For standard HTML tags with CSS behavior that needs application-specific handling, pdfHTML provides extension points. A custom tag-worker factory can handle custom markup; a custom ICssApplier can provide special CSS application behavior for a standard tag. These are extensions to implement and register, not automatic support for arbitrary custom elements or every CSS property.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesChoose between pdfHTML, XML Worker, and WebView printing
| Approach | Best fit | Important constraints |
|---|---|---|
| iText pdfHTML with iText 7 | New iText-based HTML/CSS-to-PDF conversion, with iText layout and configuration options. | Requires Android-specific dependencies and resolvable linked resources. Browser-equivalent CSS behavior is not guaranteed; validate features against the chosen release. |
| iText 5 XML Worker | Maintaining an existing iText 5 integration where migration is not currently practical. | Legacy route with narrower CSS and layout support. Input should be XHTML, not merely browser-tolerant HTML. |
| Android WebView printing | Printing a rendered HTML page through Android’s platform workflow when its printing constraints suit the app. | Android documents that CSS print attributes such as landscape are unsupported, headers and footers cannot be added, and a WebView handles only one print job at a time. |
WebView printing is a platform printing workflow, not iText PDF generation. Choose it when the WebView’s rendering and printing behavior meets the product’s needs; choose pdfHTML when the application needs iText’s conversion pipeline and its configuration and extension options.
If you still use XML Worker, supply XHTML
XML Worker expects XML-compatible markup. Browser-tolerant HTML that omits closing tags or uses malformed nesting can fail or render incorrectly. Close elements, use XML-compatible empty elements such as <br />, and supply CSS through XMLWorkerHelper.parseXHtml or a CSS resolver. This is a maintenance path for existing iText 5 projects, not the recommended starting point for a new iText 7 integration.
Check licensing before shipping
iText’s pdfHTML installation guidance states that noncommercial use must comply with the AGPL. Closed-source or commercial use requires a commercial license for both iText Core and pdfHTML, together with the compatible license-key library. Verify the compatibility matrix for the exact versions selected and confirm that the intended use fits the license before releasing the app.
Troubleshoot common conversion problems
The external stylesheet appears to be ignored
- Cause: The
hrefis relative and pdfHTML has no base URI that resolves it, or the target is not accessible from the app. - Fix: Set
ConverterProperties.setBaseUrito the directory or URI that contains the referenced resources. Check the path and capitalization, and confirm the resource is available in the app’s storage or packaged-resource setup.
Images or custom fonts are missing
- Cause: The referenced file cannot be resolved, or a custom font is not registered for conversion.
- Fix: Verify each resource URL relative to the configured base URI. For custom fonts, configure a
FontProviderand confirm both the font file location and the CSS font-family name.
The PDF differs from the browser preview
- Cause: pdfHTML translates supported CSS into PDF layout; it does not promise to reproduce a browser’s rendering in every case.
- Fix: Isolate the layout rule that differs and test it with your exact pdfHTML release. Pay particular attention to pagination, floats, fixed positioning, tables, and print media declarations. Use a custom tag worker or CSS applier only when the required behavior needs an extension.
XML Worker rejects or mishandles the HTML
- Cause: The input is HTML tolerated by browsers but not well-formed XHTML.
- Fix: Close tags, correct nesting, and use XML-compatible empty elements. Keep in mind that XML Worker is the legacy iText 5 option and has narrower CSS support.
The app builds with incompatible iText artifacts
- Cause: Core and pdfHTML are from different release lines, or Android-specific and other artifacts are mixed without compatibility verification.
- Fix: Select compatible Android artifacts from iText’s Android repository and align modules to the same supported release line. Consult iText’s current installation guidance and compatibility information rather than guessing versions.
Or skip the browser setup
If the page you need is already available at a URL and your goal is to capture that rendered webpage, ScreenshotNeo can return a screenshot or PDF with one GET request. This is a different workflow from converting an app-generated HTML string with iText: use pdfHTML for that in-app conversion requirement.
For a webpage capture saved as an image, the cURL request below uses the documented API shape. Replace the example target with the page you want to capture and put your API key in the request.
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 API documentation for request details. ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. It also has an MCP server with screenshot tools for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.
Frequently Asked Questions
Can pdfHTML convert HTML supplied as a string?
The core conversion API accepts streams; wrap the HTML text in an input stream using the encoding your document uses, then pass that stream to the converter.
Does WebView printing produce an iText PDF?
No. It is Android’s platform printing workflow, separate from iText’s PDF generation.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Can I use pdfHTML without custom fonts?
Yes. Configure a FontProvider when your document needs custom fonts; otherwise, use the converter’s default font handling and verify the output.
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.

