The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use iText’s modern itext.pdfhtml add-on and the HtmlConverter.ConvertToPdf API. “iTextSharp” refers to the older iText 5 .NET line; current .NET Core projects should use iText Core with pdfHTML. Install matching package versions, set a base URI for relative assets, and choose AGPL or a commercial license before shipping a closed-source application.
Install the current HTML-to-PDF packages
From your .NET project directory, add pdfHTML with NuGet:
dotnet add package itext.pdfhtml --version <desired-version>
Choose a version supported by your target .NET runtime and keep itext.pdfhtml aligned with the corresponding iText Core version. The vendor’s installation guidance and compatibility information are at iText pdfHTML. If you prefer Visual Studio, use Manage NuGet Packages, search for itext.pdfhtml, and install the required version. The package brings in the iText Core components needed by the converter.
Convert an HTML file to PDF
This is the smallest useful file-based example. It opens the HTML, creates the PDF, and tells pdfHTML where to resolve relative images, stylesheets, and fonts.
#1 Best Overall
using System.IO;
using iText.Html2pdf;
using iText.Html2pdf.Converter;
var htmlPath = Path.GetFullPath("invoice.html");
var pdfPath = Path.GetFullPath("invoice.pdf");
var properties = new ConverterProperties()
.SetBaseUri(Path.GetDirectoryName(htmlPath)!);
using var html = File.OpenRead(htmlPath);
using var pdf = File.Create(pdfPath);
HtmlConverter.ConvertToPdf(html, pdf, properties);
SetBaseUri is important: a reference such as css/site.css or images/logo.png is resolved relative to that directory. Without a correct base URI, the PDF can contain unstyled text or missing images even though the HTML works in a browser. The exact namespaces and overloads can vary with the package version, so check the API for the version you selected.
Use a string or stream instead
For HTML generated at runtime, use the corresponding HtmlConverter.ConvertToPdf overload that accepts a string or stream. Keep the base URI whenever the markup contains relative resources.
using iText.Html2pdf;
using iText.Html2pdf.Converter;
string html = "<html><body><h1>Receipt</h1><p>Paid</p></body></html>";
var properties = new ConverterProperties()
.SetBaseUri(AppContext.BaseDirectory);
HtmlConverter.ConvertToPdf(html, "receipt.pdf", properties);
If your installed version exposes a stream-based overload instead of the shown file-path overload, create a FileStream and pass it to that overload. The conversion concept and resource-resolution requirement remain the same.
Make CSS, images, and fonts reliable
Stylesheets
Prefer ordinary linked stylesheets with paths that are valid from the base directory:
<link rel="stylesheet" href="css/print.css">
Package the css directory with the application or copy it to the deployment directory. If you generate HTML in a temporary folder, set the base URI to that folder or use absolute, controlled paths.
Images
Use file paths or data URLs that your process can access. Check case sensitivity on Linux and ensure the worker account has read permission. A browser’s ability to display an image does not prove that the server-side converter can read it.
Rank #2
<img src="images/company-logo.png" alt="Company logo">
Give meaningful images alternative text. It helps accessibility and makes the document understandable when images cannot be rendered.
Recommended Free Tools
Fonts
Install or deploy the fonts required by your design and verify that the conversion process can read them. For predictable output across machines, keep font files with the application and configure them according to the pdfHTML version’s font-provider APIs. Test licenses for any font files you redistribute. If a font is unavailable, text may fall back to another typeface or show different line breaks.
Remote resources and security
Do not assume a server can fetch every URL that a browser can. Firewalls, authentication, DNS, and certificate policy can block remote CSS or images. A safer production pattern is to download approved assets yourself, store them in a controlled directory, and use a base URI there. Treat user-supplied HTML and URLs as untrusted input; constrain file access and outbound requests in the hosting environment.
What replaced HTMLWorker?
HTMLWorker was an iText 5-era helper intended for small, simple snippets. It did not support every HTML tag or CSS file and was removed from recent iText versions. XML Worker and copied iText 5 examples are therefore not the modern full-page solution. The migration target is iText 7 or later with the pdfHTML add-on, which is designed to convert HTML and CSS into standards-oriented PDFs.
When migrating, replace parser-specific code with a ConverterProperties instance and an HtmlConverter call. Then compare representative documents: tables, page breaks, images, custom fonts, headers and footers, and any selectors that matter to your design.
Free tools Windows power users keep installed
One-click scans. No signup required.
CSS and browser-behavior limits
pdfHTML is not a browser engine. It converts supported HTML and CSS; it does not reproduce every browser feature or execute a browser’s complete layout and JavaScript stack. Advanced CSS, animation, canvas, client-side rendering, and JavaScript-dependent content need explicit testing. If the page is empty until JavaScript runs, generate the final HTML first or use a browser-based rendering workflow instead.
Build a small compatibility fixture for your application. Include the CSS constructs, fonts, right-to-left text, long tables, page-break rules, SVG or raster images, and external resources that your real documents use. Keep the fixture under automated tests so a package upgrade reveals layout changes before production.
Licensing a closed-source .NET Core application
Licensing is a deployment decision, not merely a NuGet setting. iText’s installation guidance says that non-commercial use of pdfHTML requires accepting the AGPL license, while commercial use requires purchased commercial licenses for both iText Core and pdfHTML. Review the current terms at iText’s licensing information before distributing your application.
AGPL path
If your use qualifies as non-commercial and you can comply with the AGPL obligations, document that decision and include the required notices and source-offer obligations for your distribution model. Have counsel review any network-service scenario; “not shipping an executable” does not automatically answer every license question.
Commercial path
For proprietary or commercial software, obtain the appropriate iText Core and pdfHTML commercial licenses. For iText 7.2 and newer, the licensing guide documents JSON license files and the licensing-base library. Load the license before other iText API calls. iText 7.1.x and older use XML license files and the older license-key library, so do not copy configuration between those generations.
Accessibility, standards, and document quality
pdfHTML is described by the project documentation as producing standards-compliant PDFs that are accessible, searchable, and usable for indexing. That capability does not make every source document automatically accessible. Use semantic headings, labels, table headers, alternative text, sufficient contrast, and a logical reading order in the HTML. Inspect the resulting PDF with your accessibility and archival tools and correct issues in the source markup or converter configuration.
Performance and deployment guidance
There is no universal throughput or memory figure for pdfHTML. Conversion cost depends on page count, image dimensions, fonts, CSS complexity, and concurrency. Measure with documents representative of your workload in the same .NET Core environment you will deploy.
Rank #4
- Reuse immutable configuration where safe, but create separate output streams and job state per conversion.
- Bound concurrent conversions so large images cannot exhaust process memory.
- Resize oversized source images before conversion and avoid embedding data that the document does not need.
- Write PDFs to a stream or temporary file with enough disk space; check the output stream for errors before returning a download.
- Log the package versions, document identifier, elapsed time, and failure reason, but avoid logging sensitive document contents.
- Warm up the application and test cold-start behavior if conversion runs in short-lived workers.
Troubleshooting common failures
“The type or namespace iText… could not be found”
Confirm that itext.pdfhtml is installed in the project that compiles the code, restore NuGet packages, and verify that your using directives match the installed version. Do not mix snippets from iText 5, iText 7.1, and iText 7.2 without checking their APIs.
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 minutePDF is created but CSS is missing
Set ConverterProperties.SetBaseUri to the directory that actually contains the stylesheet. Confirm the relative URL from the HTML file, filename casing, deployment contents, and read permissions.
Images are blank or missing
Resolve the image path from the configured base URI, test the process account’s access, and verify that the file format is supported. For remote images, check network access and authentication; copying approved assets locally is usually more deterministic.
Text wraps differently or fonts are substituted
Deploy the intended font files, configure the appropriate font provider for your version, and verify licensing. Compare page width, font metrics, and CSS declarations rather than assuming browser output is the expected PDF output.
JavaScript-generated content is absent
pdfHTML does not provide a full browser execution environment. Render the data into final HTML before conversion, or choose a browser-based PDF workflow when the page genuinely depends on client-side execution.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →License or watermark-related errors
Check whether your use is covered by AGPL or requires commercial licensing. For licensed deployments, use the license-file format and licensing library that match your iText generation, and load the license before invoking iText APIs.
Best Value
Conversion is slow or runs out of memory
Profile representative documents, inspect image dimensions, limit concurrency, and process large jobs in a worker with explicit memory and timeout limits. Because official materials do not publish a universal benchmark, use your own measurements rather than a quoted pages-per-second expectation.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your real requirement is a PDF or image of a publicly reachable web page rather than server-side control of an HTML document, ScreenshotNeo provides a website screenshot API. It accepts a URL and can return PNG, JPEG, WebP, or PDF. Before capture, it accepts consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing result in X-Page-Verdict and X-Billed headers.
For a simple URL capture, the API call is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Use the API’s PDF output option when you need a PDF rather than the shown WebP file. See the complete request options in the ScreenshotNeo documentation.
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 glitchesPython
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(`ScreenshotNeo returned ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo also offers full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device and viewport controls, retina scale, custom CSS and JavaScript, clicks before capture, selector hiding, waits for selectors, delays or network idle, request and resource blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. An MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account to try it.
Choosing the right approach
| Requirement | Best fit | Reason |
|---|---|---|
| Generate PDFs from application data and local templates | iText Core plus pdfHTML | HTML, CSS, assets, fonts, and licensing are controlled in your .NET process. |
| Reproduce a public web page’s rendered state | ScreenshotNeo | It captures a URL and can remove consent UI and other overlays before capture. |
| JavaScript-heavy browser layouts | A browser-based workflow | pdfHTML is not a browser engine; test or render the page after client-side execution. |
| Closed-source commercial deployment | pdfHTML with a commercial license, or a service whose terms fit your use | AGPL and commercial obligations differ and must be decided before release. |
Frequently Asked Questions
Can I keep the iTextSharp package name in a new .NET Core project?
You can encounter legacy iTextSharp code, but current full-page HTML/CSS conversion should be planned around iText Core and the separately installed pdfHTML add-on. Treat old package and API names as migration work, not as the target architecture.
Does setting a base URI make remote assets safe to use?
No. A base URI resolves relative references; it does not grant network access, authentication, or permission to read arbitrary files. Control and validate the assets your service is allowed to load.
Should I benchmark before selecting a conversion design?
Yes. Render representative documents with your actual fonts, images, concurrency, and hosting limits, then record latency and memory. Published materials do not establish a universal throughput number.
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.

