IRONSOFTWAREHOME

How to Use Web Assets & Optimize PDFs in C# for Performance

Kye Stuart
Kye Stuart
Updated: August 2, 2026

With over 100 features, IronPDF is designed to simplify PDF generation and manipulation tasks for .NET developers. This library is a one-stop solution for all your PDF needs, eliminating the need to install any third-party tools or Adobe Acrobat.

One crucial aspect that IronPDF covers is its extensive support for web assets. These tools allow the smooth use of HTML, JavaScript, web fonts, and more within your PDF documents. With this, you can create truly unique PDF documents.

IronPDF also provides impressive performance when generating and working with PDF files. This ensures smooth PDF operations without straining your system, especially when working with performance-intensive PDF tasks such as processing large batches, big files, and more.

Quickstart: Integrate Web Assets and Optimize PDFs Efficiently

This quick start guide demonstrates how to enhance your PDFs by adding web assets like images and fonts using IronPDF. With just a few lines of code, you can significantly improve the performance and visual quality of your PDF documents. Whether you're embedding a company logo or custom fonts, IronPDF makes the process fast and straightforward, ensuring your PDFs are both optimized and visually engaging.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello Performance</h1>");
    pdf.Flatten();
    pdf.CompressAndSaveAs("fast-optimized.pdf", 50);
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer
Table of Contents

Implement Web Assets into your PDFs

IronPDF's reliable support for web assets enables developers with complete control over the appearance of their PDF documents. From its comprehensive support for HTML, CSS, and JavaScript for a pixel-perfect rendering of HTML content to PDF, to the ability to implement custom fonts and images for visually appealing elements within the document, IronPDF's support for modern web standards and assets enables developers to produce high-quality, visually appealing PDFs effortlessly.

Working with Dynamic Web Content

Let's start by exploring how IronPDF simplifies the process of creating PDF documents from HTML content, complete with CSS styling and JavaScript elements. This straightforward process instills confidence in developers, knowing that they can easily convert their web assets into PDFs.

Debug HTML with Chrome

IronPDF's powerful rendering engine ensures pixel-perfect rendering of any HTML content. This means that the PDFs you render from HTML content will look exactly the same as the HTML does within a Chrome browser, providing a reliable and consistent rendering experience.

// Pixel Perfect HTML Formatting Settings
IronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // or Screen

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

CSS (Screen & Print)

CSS controls the design and layout of HTML content. Through its support for CSS styling, IronPDF can produce visually appealing PDF documents while maintaining the original layout and styling of the converted HTML content.

using IronPdf;
using IronPdf.Rendering;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Change the paper size to small
renderer.RenderingOptions.SetCustomPaperSizeinPixelsOrPoints(600, 400);

// Choose screen or print CSS media
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;

// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableHeader.html");

pdf.SaveAs("tableHeader.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Images (jpg, png, svg, gif, etc.)

Enhance your PDFs with visual elements using images. When you embed images into your PDF document with IronPDF, the images will be viewable without relying on the internet or working links. This means you can add visually appealing images to attract readers' attention, add images that contain more information for your PDF's topic, and more.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

string html = @"<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>";

// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

// Export PDF
pdf.SaveAs("embedImage.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

JavaScript (Custom Render Delays)

Often, HTML content may contain interactive and dynamic elements that can be lost during the conversion process with some PDF libraries. IronPDF's support for JavaScript ensures that converted content maintains its original interactive elements.

using IronPdf;

string htmlWithJavaScript = @"<h1>This is HTML</h1>
<script>
    document.write('<h1>This is JavaScript</h1>');
    window.ironpdf.notifyRender();
</script>";

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Enable JavaScript
renderer.RenderingOptions.EnableJavaScript = true;
// Set waitFor for JavaScript
renderer.RenderingOptions.WaitFor.JavaScript(500);

// Render HTML contains JavaScript
var pdfJavaScript = renderer.RenderHtmlAsPdf(htmlWithJavaScript);

// Export PDF
pdfJavaScript.SaveAs("javascriptHtml.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Use WaitFor to Delay PDF Render

When rendering PDF documents, there are times when the necessary assets haven't been fetched yet, resulting in an incomplete rendering. With IronPDF, we can specify a render delay to ensure that all assets are obtained before rendering.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render as soon as the page is loaded
renderer.RenderingOptions.WaitFor.PageLoad();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Fonts (Web & Icon)

By adding custom fonts to your PDF documents, you can create truly unique PDF files that fit the needs of the type of document you're making. IronPDF simplifies this process, allowing you to capture users' attention with clean, yet visually appealing, font types or utilize web fonts to ensure consistent text across different machines, regardless of the local font availability on that computer.

using IronPdf;

// HTML contains webfont
var html = @"<link href=""https://fonts.googleapis.com/css?family=Lobster"" rel=""stylesheet"">
<p style=""font-family: 'Lobster', serif; font-size:30px;"" > Hello Google Fonts</p>";

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Wait for font to load
renderer.RenderingOptions.WaitFor.AllFontsLoaded(2000);

// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

// Export the PDF
pdf.SaveAs("font-test.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Use SVG Graphics

Aside from rendering images to PDF, IronPDF also offers the ability to render SVG graphics into PDFs.

using IronPdf;

string html = "<img src='https://ironsoftware.com/img/svgs/new-banner-svg.svg' style='width:100px'>";

ChromePdfRenderer renderer = new ChromePdfRenderer();
renderer.RenderingOptions.WaitFor.RenderDelay(1000);

PdfDocument pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("svgToPdf.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Manage Fonts

Choosing the correct font and being able to customize and embed fonts are crucial aspects when creating PDFs. With IronPDF, you can manage, retrieve, and add fonts all in one package with intuitive methods.

using IronPdf;
using IronPdf.Fonts;
using System.Collections.Generic;

// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");

// Retreive font
PdfFontCollection fonts = pdf.Fonts;

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Support UTF-8 and International Languages

Thanks to its adherence to Chrome standards, IronPDF supports the use of UTF-8 Encoding within PDF documents. This ensures that any characters used are correctly rendered, including any foreign languages used in the original content. All of it will be rendered correctly in the final PDF document.

using IronPdf;

const string html_with_utf_8 =
    @"<p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。
    文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。
    失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。
    陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p>
    <p>
    أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملاً المنتصر,
    ٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط,
    زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل.
    </p>
    <p>
    ภคันทลาพาธสตาร์เซฟตี้ แชมป์ มาร์เก็ตติ้งล้มเหลวโยเกิร์ต แลนด์บาบูนอึมครึม รุสโซ แบรนด์ไคลแม็กซ์ พิซซ่าโมเดลเสือโคร่ง ม็อบโซนรายชื่อ
    แอดมิชชั่น ด็อกเตอร์ พะเรอ มาร์คเจไดโมจิราสเบอร์รี เอนทรานซ์ออดิชั่นศิลปวัฒนธรรมเปราะบาง โมจิซีเรียสวอลนัตทริปลีเมอร์ ทิป วาไรตี้บิ๊กเมเปิล
    </p>";

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.InputEncoding = System.Text.Encoding.UTF8;

var pdf = renderer.RenderHtmlAsPdf(html_with_utf_8);
pdf.SaveAs("Unicode.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Base URLs & Asset Encoding

IronPDF allows you to set a Base URL, enabling relative paths in your HTML, such as images, CSS, or JavaScript, to load correctly when rendering to PDF. You can also embed assets with base64 encoding to keep everything self-contained and internet-free.

using IronPdf;

// Instantiate ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

string baseUrl = @"C:\site\assets\";
string html = "<img src='icons/iron.png'>";

// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html, baseUrl);

// Export PDF
pdf.SaveAs("html-with-assets.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Render WebGL Sites

WebGL is a commonly used tool for creating interactive 3D graphics, but converting them into a static PDF can be a challenging task. With IronPDF, this process is made as smooth as possible, providing developers with a sense of ease and confidence in their ability to convert complex web assets into PDFs.

using IronPdf;

// Configure IronPdf settings
IronPdf.Installation.SingleProcess = true;
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Hardware;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Set delay before rendering
renderer.RenderingOptions.WaitFor.RenderDelay(5000);

// Render from URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://docs.mapbox.com/mapbox-gl-js/example/geojson-layer-in-slot/");

pdf.SaveAs("webGL.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Chrome PDF Rendering Engine

IronPDF utilizes the powerful Chromium engine, allowing users to create pixel-perfect PDFs with CSS and JavaScript. This creates a what-you-see-is-what-you-get scenario, giving you peace of mind and eliminating any doubts when it comes to converting them to PDFs. The use of this engine ensures high compatibility and performance in PDF rendering.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.PrintHtmlBackgrounds = false;
renderer.RenderingOptions.CreatePdfFormsFromHtml = false;

PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.google.com/");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.

David Jones

Lead Software Engineer, Agorus Build

View case study

Performance and Compression

When working with large PDF files or generating big batches of PDFs, performance is key to a smooth process. This is where IronPDF stands out, with impressive performance speeds when working with PDFs of all sizes. IronPDF provides consistent, smooth-running performance for all your PDF tasks.

In this section, we'll take a closer look at some of the features and tools that IronPDF offers to ensure smooth performance, regardless of the tasks you need to run.

PDF Compression

Please note: Earlier compression methods like CompressImages, CompressStructTree, and Compress(CompressionOptions) are deprecated.

Compressing images within a PDF is a convenient way to reduce the file size of a PDF document significantly. Larger PDF files often contain multiple images, which can dramatically inflate the overall size of the PDF file. By compressing these files, you can make them easier to share and store, saving you time and resources.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

// Quality 40 re-encodes every embedded image as a low-quality JPEG, which is
// where most of the file-size saving comes from in image-heavy PDFs
pdf.CompressAndSaveAs("compressed.pdf", 40);
C#

If you need the compressed output without writing to disk, use CompressPdfToBytes to get a byte array.

byte[] compressed = pdf.CompressPdfToBytes();

Or use CompressPdfToStream to get a Stream.

using var stream = pdf.CompressPdfToStream();

For granular control over the compression pipeline, pass an AdvancedCompressionOptions object. It exposes image DPI downsampling (TargetImageDpi), JPEG re-encoding quality (JpegQuality), and the zlib compression level in a single configuration object, while the original CompressAndSaveAs(outputPath, quality, removeStructureTree) overload keeps working unchanged.

pdf.CompressAndSaveAs("compressed.pdf", new AdvancedCompressionOptions
{
    JpegQuality = 70,
    TargetImageDpi = 150
});
C#

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Async & Multithreading

IronPDF supports asynchronous PDF generation using the RenderHtmlAsPdfAsync method. This powerful feature enables you to convert HTML to PDF without impacting your application's performance, ensuring consistent results. It's beneficial for handling multiple documents or integrating into responsive web APIs, giving you complete control over your application's performance.

using IronPdf;
using System.Threading.Tasks;

// Instantiate ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

string[] htmlStrings = {"<h1>Html 1</h1>", "<h1>Html 2</h1>", "<h1>Html 3</h1>"};

// Create an array to store the tasks for rendering
var renderingTasks = new Task<PdfDocument>[htmlStrings.Length];

for (int i = 0; i < htmlStrings.Length; i++)
{
    int index = i; // Capturing the loop variable
    renderingTasks[i] = Task.Run(async () =>
    {
        // Render HTML to PDF
        return await renderer.RenderHtmlAsPdfAsync(htmlStrings[index]);
    });
}

// Wait for all rendering tasks to complete
// await Task.WhenAll(renderingTasks);

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Custom Logging

IronPDF enables custom logging by allowing you to route log messages to your logger. By setting LoggingMode to LoggingModes.Custom and assigning your custom logger to CustomLogger, you can control how and where log messages are handled. This is useful for integrating IronPDF logs into your existing logging infrastructure.

IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.Custom;
IronSoftware.Logger.CustomLogger = new CustomLoggerClass("logging");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Flatten PDFs

The Flatten method in IronPDF is a powerful tool that allows you to make PDFs interactive and fillable widgets non-editable for various purposes. It flattens the PDF, preserving its visual layout while preventing any further editing, ensuring the integrity of your documents.

using IronPdf;

// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("before.pdf");

// Flatten the pdf
pdf.Flatten();

// Save as a new file
pdf.SaveAs("after_flatten.pdf");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

PDF Viewing and Printing

This functionality allows users to generate PDF files instead of sending documents directly to a printer. When the Print is used, the system creates a PDF file that is saved on the local machine. You can also specify a different printer by providing the printer name to the Print method.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>");

// Send the document to "Microsoft Print to PDF" printer
pdf.Print("Microsoft Print to PDF");

For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive how-to guide.

Conclusion

IronPDF enables .NET developers with the flexibility to create professional, high-quality PDFs. It integrates modern web assets and delivers top-tier performance. Whether you're rendering dynamic HTML content, embedding custom fonts and images, or optimizing large-scale PDF generation through compression and multithreading, IronPDF offers the flexibility and power you need - all without external dependencies.

By combining rich asset support with performance-focused tools like async rendering and custom logging, IronPDF ensures your applications remain fast, scalable, and visually consistent. Whether you're building a simple report or an enterprise-level document automation system, IronPDF makes it easy to deliver beautiful and efficient PDF documents every time.

Now that you've seen what IronPDF can do, it's time to start building smarter, faster PDF workflows in your .NET projects.

Frequently Asked Questions

What are web assets, and how can they be used in IronPDF?

Web assets in IronPDF refer to HTML, JavaScript, web fonts, and more, which can be integrated into your PDF documents. This allows you to create PDFs with rich content, precise layout, and styling as seen in web pages.

How can I enhance PDF performance using IronPDF?

IronPDF provides tools for optimizing PDF performance by supporting web assets and effective compression. You can use the `Flatten` and `CompressAndSaveAs` methods to ensure your PDFs are efficient and optimized for size and processing speed.

Does IronPDF support custom fonts in PDF documents?

Yes, IronPDF allows you to incorporate web and custom fonts into your PDF documents, providing the flexibility to maintain consistent typography and design, regardless of the viewer's local fonts.

Can IronPDF handle dynamic web content when rendering PDFs?

IronPDF supports the use of JavaScript, allowing it to maintain the interactivity and dynamic elements of HTML content when converting to PDFs. This ensures that your PDFs reflect the original content's functionality.

Is it possible to compress PDF files with IronPDF?

Yes, IronPDF provides features for compressing PDF documents. You can use methods like `CompressAndSaveAs` to adjust image qualities and other elements to produce smaller, more manageable files.

How can IronPDF support UTF-8 encoding and international languages?

IronPDF supports UTF-8 encoding, allowing PDFs to accurately render characters and languages from original documents. This includes complex scripts and international symbols, ensuring perfect representation.

What are the advantages of using the Chrome PDF Rendering Engine in IronPDF?

The Chrome PDF Rendering Engine ensures that PDFs created with IronPDF have high fidelity and accuracy, mirroring the layout and design of web pages as viewed in Chrome, benefiting from modern web standards compliance.

How does IronPDF facilitate asynchronous PDF generation?

IronPDF supports asynchronous generation of PDFs using `RenderHtmlAsPdfAsync`, allowing developers to render PDFs in a non-blocking way, which is beneficial for web applications handling multiple documents simultaneously.

What functionality does IronPDF offer for embedding images?

IronPDF supports embedding various image formats directly into PDF documents. Images can be embedded so they are viewable offline, enhancing the visual appeal and information content of the PDFs.

Kye Stuart
Technical Writer

Kye Stuart merges coding passion and writing skill at Iron Software. Educated at Yoobee College in software deployment, they now transform complex tech concepts into clear educational content. Kye values lifelong learning and embraces new tech challenges.

...
Read More

Ready to Get Started?

Nuget Downloads 21,105,021Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999