# How to Use Web Assets & Optimize PDFs in C# for Performance
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.
*as-heading:2(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.
```cs
:title=Enhance PDFs Quickly with IronPDF
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello Performance</h1>");
pdf.Flatten();
pdf.CompressAndSaveAs("fast-optimized.pdf", 50);
```
*as-heading:2(Table of Contents)*
- **Support Web Assets**
- [Debug HTML with Chrome](#anchor-debug-html-with-chrome)
- [CSS (Screen & Print)](#anchor-css-screen-print)
- [Images (jpg, png, svg, gif, etc.)](#anchor-images-jpg-png-svg-gif-etc)
- [JavaScript (Custom Render Delays)](#anchor-javascript-custom-render-delays)
- [Use WaitFor to Delay PDF Render](#anchor-use-waitfor-to-delay-pdf-render)
- [Fonts (Web & Icon)](#anchor-fonts-web-icon)
- [Use SVG Graphics](#anchor-use-svg-graphics)
- [Manage Fonts](#anchor-manage-fonts)
- [Support UTF-8 and International Languages](#anchor-support-utf-8-and-international-languages)
- [Base URLs & Asset Encoding](#anchor-base-urls-asset-encoding)
- [Render WebGL Sites](#anchor-render-webgl-sites)
- [Chrome PDF Rendering Engine](#anchor-chrome-pdf-rendering-engine)
- **Performance and Compression**
- [PDF Compression](#anchor-pdf-compression)
- [Async & Multithreading](#anchor-async-multithreading)
- [Custom Logging](#anchor-custom-logging)
- [Flatten PDFs](#anchor-flatten-pdfs)
- **PDF Viewing and Printing**
- [Print to a Physical Printer](#anchor-print-to-physical-printer)
- **Conclusion**
## 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.
```cs
// 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](https://ironpdf.com/how-to/export-save-pdf-csharp/).
### 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.
```cs
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](https://ironpdf.com/how-to/html-to-pdf-responsive-css/).
### 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.
```cs
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](https://ironpdf.com/how-to/html-to-pdf-responsive-css/).
### 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.
```cs
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](https://ironpdf.com/how-to/javascript-to-pdf/).
### 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.
```cs
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](https://ironpdf.com/how-to/waitfor/).
### 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.
```cs
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](https://ironpdf.com/how-to/webfonts-webicons/).
### Use SVG Graphics
Aside from rendering images to PDF, IronPDF also offers the ability to render SVG graphics into PDFs.
```cs
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](https://ironpdf.com/how-to/SVGs/).
### 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.
```cs
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](https://ironpdf.com/how-to/manage-fonts/).
### 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.
```cs
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](https://ironpdf.com/how-to/utf-8/).
### 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.
```cs
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](https://ironpdf.com/how-to/base-urls/).
### 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.
```cs
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](https://ironpdf.com/how-to/render-webgl/).
### 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.
```cs
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](https://ironpdf.com/how-to/ironpdf-2021-chrome-rendering-engine-eap/).
## 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
[[i:(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.
```cs
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);
```
If you need the compressed output without writing to disk, use `CompressPdfToBytes` to get a byte array.
```cs
byte[] compressed = pdf.CompressPdfToBytes();
```
Or use `CompressPdfToStream` to get a Stream.
```cs
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.
```cs
pdf.CompressAndSaveAs("compressed.pdf", new AdvancedCompressionOptions
{
JpegQuality = 70,
TargetImageDpi = 150
});
```
For a more detailed explanation of this code snippet and to explore its additional functionality, please refer to our comprehensive [how-to guide](https://ironpdf.com/how-to/pdf-compression/).
### 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.
```cs
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](https://ironpdf.com/how-to/async/).
### 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.
```cs
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](https://ironpdf.com/how-to/custom-logging/).
### 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.
```cs
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](https://ironpdf.com/how-to/pdf-image-flatten-csharp/).
## PDF Viewing and Printing
### Print to Physical Printer
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.
```cs
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](https://ironpdf.com/how-to/print-pdf/).
## 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.
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.
1Install IronPDF with NuGet Package Manager
PM > Install-Package IronPdf
Install-Package IronPdf
2Copy and run this code snippet.
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello Performance</h1>");pdf.Flatten();pdf.CompressAndSaveAs("fast-optimized.pdf", 50);
var pdf = new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf("<h1>Hello Performance</h1>");
pdf.Flatten();
pdf.CompressAndSaveAs("fast-optimized.pdf", 50);
C#
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
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 SettingsIronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // or Screen
// Pixel Perfect HTML Formatting Settings
IronPdf.ChromePdfRenderer renderer = new IronPdf.ChromePdfRenderer();
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // or Screen
' Pixel Perfect HTML Formatting SettingsDim renderer As New IronPdf.ChromePdfRenderer()renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print' or Screen
' Pixel Perfect HTML Formatting Settings
Dim renderer As 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 smallrenderer.RenderingOptions.SetCustomPaperSizeinPixelsOrPoints(600, 400);// Choose screen or print CSS mediarenderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;// Render HTML to PDFPdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableHeader.html");pdf.SaveAs("tableHeader.pdf");
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");
ImportsIronPdfImportsIronPdf.RenderingPrivate renderer As New ChromePdfRenderer()' Change the paper size to smallrenderer.RenderingOptions.SetCustomPaperSizeinPixelsOrPoints(600, 400)' Choose screen or print CSS mediarenderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print' Render HTML to PDFDim pdf AsPdfDocument = renderer.RenderHtmlFileAsPdf("tableHeader.html")pdf.SaveAs("tableHeader.pdf")
Imports IronPdf
Imports IronPdf.Rendering
Private renderer As 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
Dim pdf As PdfDocument = 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 PDFPdfDocument pdf = renderer.RenderHtmlAsPdf(html);// Export PDFpdf.SaveAs("embedImage.pdf");
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");
ImportsIronPdfDim renderer As New ChromePdfRenderer()Dim html AsString = "<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>"' Render HTML to PDFDim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html)' Export PDFpdf.SaveAs("embedImage.pdf")
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim html As String = "<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>"
' Render HTML to PDF
Dim pdf As PdfDocument = 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 Renderervar renderer = new ChromePdfRenderer();// Enable JavaScriptrenderer.RenderingOptions.EnableJavaScript = true;// Set waitFor for JavaScriptrenderer.RenderingOptions.WaitFor.JavaScript(500);// Render HTML contains JavaScriptvar pdfJavaScript = renderer.RenderHtmlAsPdf(htmlWithJavaScript);// Export PDFpdfJavaScript.SaveAs("javascriptHtml.pdf");
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");
ImportsIronPdfPrivate htmlWithJavaScript AsString = "<h1>This is HTML</h1><script> document.write('<h1>This is JavaScript</h1>'); window.ironpdf.notifyRender();</script>"' Instantiate RendererPrivate renderer = New ChromePdfRenderer()' Enable JavaScriptrenderer.RenderingOptions.EnableJavaScript = True' Set waitFor for JavaScriptrenderer.RenderingOptions.WaitFor.JavaScript(500)' Render HTML contains JavaScriptDim pdfJavaScript = renderer.RenderHtmlAsPdf(htmlWithJavaScript)' Export PDFpdfJavaScript.SaveAs("javascriptHtml.pdf")
Imports IronPdf
Private htmlWithJavaScript As String = "<h1>This is HTML</h1>
<script>
document.write('<h1>This is JavaScript</h1>');
window.ironpdf.notifyRender();
</script>"
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
' Enable JavaScript
renderer.RenderingOptions.EnableJavaScript = True
' Set waitFor for JavaScript
renderer.RenderingOptions.WaitFor.JavaScript(500)
' Render HTML contains JavaScript
Dim 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 loadedrenderer.RenderingOptions.WaitFor.PageLoad();PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>");
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>");
ImportsIronPdfDim renderer As New ChromePdfRenderer()' Render as soon as the page is loadedrenderer.RenderingOptions.WaitFor.PageLoad()Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>")
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
' Render as soon as the page is loaded
renderer.RenderingOptions.WaitFor.PageLoad()
Dim pdf As PdfDocument = 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 webfontvar 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 loadrenderer.RenderingOptions.WaitFor.AllFontsLoaded(2000);// Render HTML to PDFPdfDocument pdf = renderer.RenderHtmlAsPdf(html);// Export the PDFpdf.SaveAs("font-test.pdf");
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");
ImportsIronPdf' HTML contains webfontPrivate 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>"Private renderer As New ChromePdfRenderer()' Wait for font to loadrenderer.RenderingOptions.WaitFor.AllFontsLoaded(2000)' Render HTML to PDFDim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html)' Export the PDFpdf.SaveAs("font-test.pdf")
Imports IronPdf
' HTML contains webfont
Private 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>"
Private renderer As New ChromePdfRenderer()
' Wait for font to load
renderer.RenderingOptions.WaitFor.AllFontsLoaded(2000)
' Render HTML to PDF
Dim pdf As PdfDocument = 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");
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");
ImportsIronPdfPrivate html AsString = "<img src='https://ironsoftware.com/img/svgs/new-banner-svg.svg' style='width:100px'>"Private renderer As New ChromePdfRenderer()renderer.RenderingOptions.WaitFor.RenderDelay(1000)Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html)pdf.SaveAs("svgToPdf.pdf")
Imports IronPdf
Private html As String = "<img src='https://ironsoftware.com/img/svgs/new-banner-svg.svg' style='width:100px'>"
Private renderer As New ChromePdfRenderer()
renderer.RenderingOptions.WaitFor.RenderDelay(1000)
Dim pdf As PdfDocument = 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 PDFPdfDocument pdf = PdfDocument.FromFile("sample.pdf");// Retreive fontPdfFontCollection fonts = pdf.Fonts;
using IronPdf;
using IronPdf.Fonts;
using System.Collections.Generic;
// Import PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Retreive font
PdfFontCollection fonts = pdf.Fonts;
Imports IronPdf
Imports IronPdf.Fonts
Imports System.Collections.Generic
' Import PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Retreive font
Private fonts As PdfFontCollection = 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");
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");
ImportsIronPdfPrivate Const html_with_utf_8 AsString = "<p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。 文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。 失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。 陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p> <p> أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملاً المنتصر, ٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط, زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل. </p> <p> ภคันทลาพาธสตาร์เซฟตี้ แชมป์ มาร์เก็ตติ้งล้มเหลวโยเกิร์ต แลนด์บาบูนอึมครึม รุสโซ แบรนด์ไคลแม็กซ์ พิซซ่าโมเดลเสือโคร่ง ม็อบโซนรายชื่อ แอดมิชชั่น ด็อกเตอร์ พะเรอ มาร์คเจไดโมจิราสเบอร์รี เอนทรานซ์ออดิชั่นศิลปวัฒนธรรมเปราะบาง โมจิซีเรียสวอลนัตทริปลีเมอร์ ทิป วาไรตี้บิ๊กเมเปิล </p>"Private renderer = New ChromePdfRenderer()renderer.RenderingOptions.InputEncoding = System.Text.Encoding.UTF8Dim pdf = renderer.RenderHtmlAsPdf(html_with_utf_8)pdf.SaveAs("Unicode.pdf")
Imports IronPdf
Private Const html_with_utf_8 As String = "<p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。
文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。
失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。
陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p>
<p>
أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملاً المنتصر,
٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط,
زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل.
</p>
<p>
ภคันทลาพาธสตาร์เซฟตี้ แชมป์ มาร์เก็ตติ้งล้มเหลวโยเกิร์ต แลนด์บาบูนอึมครึม รุสโซ แบรนด์ไคลแม็กซ์ พิซซ่าโมเดลเสือโคร่ง ม็อบโซนรายชื่อ
แอดมิชชั่น ด็อกเตอร์ พะเรอ มาร์คเจไดโมจิราสเบอร์รี เอนทรานซ์ออดิชั่นศิลปวัฒนธรรมเปราะบาง โมจิซีเรียสวอลนัตทริปลีเมอร์ ทิป วาไรตี้บิ๊กเมเปิล
</p>"
Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.InputEncoding = System.Text.Encoding.UTF8
Dim 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 ChromePdfRendererChromePdfRenderer renderer = new ChromePdfRenderer();string baseUrl = @"C:\site\assets\";string html = "<img src='icons/iron.png'>";// Render HTML to PDFPdfDocument pdf = renderer.RenderHtmlAsPdf(html, baseUrl);// Export PDFpdf.SaveAs("html-with-assets.pdf");
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");
Dim renderer As New ChromePdfRenderer()Dim baseUrl AsString = "C:\site\assets\"Dim html AsString = "<img src='icons/iron.png'>"Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf(html, baseUrl)pdf.SaveAs("html-with-assets.pdf")
Dim renderer As New ChromePdfRenderer()
Dim baseUrl As String = "C:\site\assets\"
Dim html As String = "<img src='icons/iron.png'>"
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html, baseUrl)
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 settingsIronPdf.Installation.SingleProcess = true;IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Hardware;ChromePdfRenderer renderer = new ChromePdfRenderer();// Set delay before renderingrenderer.RenderingOptions.WaitFor.RenderDelay(5000);// Render from URLPdfDocument pdf = renderer.RenderUrlAsPdf("https://docs.mapbox.com/mapbox-gl-js/example/geojson-layer-in-slot/");pdf.SaveAs("webGL.pdf");
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");
ImportsIronPdf' Configure IronPdf settingsIronPdf.Installation.SingleProcess = TrueIronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.HardwareDim renderer As New ChromePdfRenderer()' Set delay before renderingrenderer.RenderingOptions.WaitFor.RenderDelay(5000)' Render from URLDim pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://docs.mapbox.com/mapbox-gl-js/example/geojson-layer-in-slot/")pdf.SaveAs("webGL.pdf")
Imports IronPdf
' Configure IronPdf settings
IronPdf.Installation.SingleProcess = True
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Hardware
Dim renderer As New ChromePdfRenderer()
' Set delay before rendering
renderer.RenderingOptions.WaitFor.RenderDelay(5000)
' Render from URL
Dim pdf As PdfDocument = 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/");
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/");
ImportsIronPdfPrivate renderer As New ChromePdfRenderer()renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Printrenderer.RenderingOptions.PrintHtmlBackgrounds = Falserenderer.RenderingOptions.CreatePdfFormsFromHtml = FalseDim pdf AsPdfDocument = renderer.RenderUrlAsPdf("https://www.google.com/")
Imports IronPdf
Private renderer As New ChromePdfRenderer()
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
renderer.RenderingOptions.PrintHtmlBackgrounds = False
renderer.RenderingOptions.CreatePdfFormsFromHtml = False
Dim pdf As PdfDocument = 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.
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.
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.
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 PDFspdf.CompressAndSaveAs("compressed.pdf", 40);
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();
byte[] compressed = pdf.CompressPdfToBytes();
Dim compressed AsByte() = pdf.CompressPdfToBytes()
Dim compressed As Byte() = pdf.CompressPdfToBytes()
Or use CompressPdfToStream to get a Stream.
using var stream = pdf.CompressPdfToStream();
using var stream = pdf.CompressPdfToStream();
net
net
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});
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 ChromePdfRendererChromePdfRenderer 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 renderingvar 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);
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);
ImportsIronPdfImportsSystem.Threading.Tasks' Instantiate ChromePdfRendererPrivate renderer As New ChromePdfRenderer()Private htmlStrings() AsString = {"<h1>Html 1</h1>", "<h1>Html 2</h1>", "<h1>Html 3</h1>"}' Create an array to store the tasks for renderingPrivate renderingTasks = New Task(OfPdfDocument)(htmlStrings.Length - 1){}For i AsInteger = 0 To htmlStrings.Length - 1 Dim index AsInteger = i ' Capturing the loop variable renderingTasks(i) = Task.Run(Async Function() ' Render HTML to PDF ReturnAwait renderer.RenderHtmlAsPdfAsync(htmlStrings(index)) End Function)Next i' Wait for all rendering tasks to complete' await Task.WhenAll(renderingTasks);
Imports IronPdf
Imports System.Threading.Tasks
' Instantiate ChromePdfRenderer
Private renderer As New ChromePdfRenderer()
Private htmlStrings() As String = {"<h1>Html 1</h1>", "<h1>Html 2</h1>", "<h1>Html 3</h1>"}
' Create an array to store the tasks for rendering
Private renderingTasks = New Task(Of PdfDocument)(htmlStrings.Length - 1){}
For i As Integer = 0 To htmlStrings.Length - 1
Dim index As Integer = i ' Capturing the loop variable
renderingTasks(i) = Task.Run(Async Function()
' Render HTML to PDF
Return Await renderer.RenderHtmlAsPdfAsync(htmlStrings(index))
End Function)
Next i
' 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");
IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.Custom;
IronSoftware.Logger.CustomLogger = new CustomLoggerClass("logging");
IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.CustomIronSoftware.Logger.CustomLogger = New CustomLoggerClass("logging")
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 FilePdfDocument pdf = PdfDocument.FromFile("before.pdf");// Flatten the pdfpdf.Flatten();// Save as a new filepdf.SaveAs("after_flatten.pdf");
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");
ImportsIronPdf' Select the desired PDF FilePrivate pdf AsPdfDocument = PdfDocument.FromFile("before.pdf")' Flatten the pdfpdf.Flatten()' Save as a new filepdf.SaveAs("after_flatten.pdf")
Imports IronPdf
' Select the desired PDF File
Private pdf As PdfDocument = 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
Print to Physical Printer
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" printerpdf.Print("Microsoft Print to PDF");
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");
ImportsIronPdfDim renderer As New ChromePdfRenderer()Dim pdf AsPdfDocument = renderer.RenderHtmlAsPdf("<h1>Test printing</h1>")' Send the document to "Microsoft Print to PDF" printerpdf.Print("Microsoft Print to PDF")
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = 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 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.