IRONSOFTWAREHOME

How to Use Rendering Options in IronPDF with C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Rendering options in IronPDF customize PDF generation through the ChromePdfRenderer class, controlling settings like margins, headers, footers, paper size, JavaScript execution, and CSS media types to create precisely formatted PDF documents from HTML, CSS, and other content sources.

Quickstart: Apply Rendering Options in C#
  1. Install IronPDF via NuGet Package Manager
  2. Create a ChromePdfRenderer instance
  3. Configure rendering options through the RenderingOptions property
  4. Render your content (HTML, Markdown, etc.) to PDF
  5. Save the resulting PDF document
  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    new IronPdf.ChromePdfRenderer { RenderingOptions = { PrintHtmlBackgrounds = true, MarginTop = 0, MarginBottom = 0, CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print, HtmlHeader = new IronPdf.HtmlHeaderFooter { HtmlFragment = "<div>My Header</div>" }, Timeout = 120000 } }
        .RenderHtmlStringAsPdf("<h1>Hello Options</h1>")
        .SaveAs("renderingOptions.pdf");
    C#
  3. 3Deploy to test on your live environment

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

Rendering options in PDF generation are settings that determine how a PDF document is created, displayed, and printed. These options include rendering form elements, enabling JavaScript, generating tables of contents, adding headers and footers, adjusting margins, setting paper sizes, and more.

The ChromePdfRenderer class in IronPDF provides various rendering options for customizing PDF generation. It includes PaperFit, a manager that controls content layout on PDF pages, offering different styles such as responsive CSS3 layouts or continuous feed. When working with complex documents, you might need to merge or split PDFs after applying rendering options.


How Do I Use Rendering Options in IronPDF?

While many rendering option properties are designed for HTML-to-PDF conversion, they work with other PDF conversion types too. Let's render Markdown to PDF and configure the output using rendering options. For HTML conversions specifically, learn about converting HTML files to PDF or converting HTML strings to PDF.

Why Should I Configure Rendering Options?

Configuring rendering options ensures PDFs generate with exact specifications: custom paper sizes, specific margins, headers and footers, or enabled JavaScript for dynamic content. This control is crucial when creating new PDFs for professional documents or reports.

What Happens When I Apply Multiple Rendering Options?

Multiple rendering options work together to create the final PDF output. Each option modifies a specific rendering aspect, and IronPDF applies them sequentially during conversion. For example, when setting both margins and headers, header content respects margin settings unless overridden using the UseMarginsOnHeaderAndFooter property.

using IronPdf;

// Instantiate a ChromePdfRenderer object, which uses a headless version of the Chrome browser
// to render HTML/CSS as a PDF document.
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Configure rendering options
// Enable printing of HTML backgrounds to ensure all styles are visible.
renderer.RenderingOptions.PrintHtmlBackgrounds = true;

// Set HTML header content using HtmlHeaderFooter.
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
    // HTML fragment to add a header at the top of every page in the PDF.
    HtmlFragment = "<h1>Header Content</h1>"
};

// Set a custom paper size for the PDF in millimeters (width and height).
renderer.RenderingOptions.SetCustomPaperSizeinMilimeters(150, 150);

// Set the top margin to zero to start the content from the very top of the page.
renderer.RenderingOptions.MarginTop = 0;

// Define a Markdown string that will be rendered as a PDF.
// Markdown text allows basic formatting like bold and italic styles.
string md = "This is some **bold** and *italic* text.";

// Render the Markdown string to a PDF document.
// The library will convert Markdown syntax into equivalent HTML before rendering it as a PDF.
PdfDocument pdf = renderer.RenderMarkdownStringAsPdf(md);

// Save the generated PDF to a file named "renderingOptions.pdf."
pdf.SaveAs("renderingOptions.pdf");

Advanced Rendering Options Example

This comprehensive example demonstrates combining multiple rendering options for professional document generation. This approach helps when you need to add headers and footers or work with custom paper sizes:

using IronPdf;
using IronPdf.Rendering;

// Create renderer with advanced options
var renderer = new ChromePdfRenderer();

// Configure paper and layout settings
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;

// Set margins for professional layout
renderer.RenderingOptions.MarginTop = 40;    // mm
renderer.RenderingOptions.MarginBottom = 40; // mm
renderer.RenderingOptions.MarginLeft = 20;   // mm
renderer.RenderingOptions.MarginRight = 20;  // mm

// Enable JavaScript for dynamic content
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.RenderDelay(2000); // Wait 2 seconds for JS to execute

// Add professional header with page numbers
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
    Height = 25,
    HtmlFragment = @"<div style='text-align: center; padding: 10px;'>
                     <span>Document Title</span> - Page {page} of {total-pages}
                     </div>",
    DrawDividerLine = true
};

// Add footer with timestamp
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
    Height = 20,
    HtmlFragment = @"<div style='text-align: center; font-size: 10px;'>
                     Generated on {date} at {time}
                     </div>"
};

// Render HTML content
string htmlContent = @"
<html>
<head>
    <style>
        body { font-family: Arial, sans-serif; }
        .content { padding: 20px; }
    </style>
</head>
<body>
    <div class='content'>
        <h1>Professional Document</h1>
        <p>This document demonstrates advanced rendering options.</p>
    </div>
</body>
</html>";

PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("professional-document.pdf");
C#

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

What Are All Available Rendering Options?

Advanced options define PDF-rendering settings like margins, paper orientation, paper size, and more. Understanding these options helps when you need to set custom margins or work with different viewport settings and zoom levels.

Which Rendering Options Are Most Commonly Used?

The most commonly used rendering options include margin settings, paper size configuration, header/footer setup, and JavaScript enabling. These options cover most PDF customization needs. For web-based content, JavaScript rendering options ensure dynamic elements render correctly.

How Do I Choose the Right Rendering Options?

Choose rendering options based on your requirements: use margin settings for print layouts, enable JavaScript for dynamic web content, configure headers/footers for professional documents, and adjust paper size for specific output formats. When working with web content, consider CSS media types for optimal rendering.

When Should I Use Advanced Rendering Options?

Use advanced rendering options for specialized features like custom CSS injection, LaTeX mathematical rendering, grayscale output, or when working with complex web applications requiring specific JavaScript execution timing. The WaitFor class provides precise control over rendering delays for complex scenarios.

Working with Form Elements

When HTML contains form elements, IronPDF automatically converts them to interactive PDF forms:

using IronPdf;

var renderer = new ChromePdfRenderer();

// Enable PDF form creation from HTML forms
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;

// HTML with form elements
string formHtml = @"
<html>
<body>
    <form>
        <label>Name: <input type='text' name='name' /></label><br>
        <label>Email: <input type='email' name='email' /></label><br>
        <label>Subscribe: <input type='checkbox' name='subscribe' /></label><br>
        <button type='submit'>Submit</button>
    </form>
</body>
</html>";

PdfDocument pdfWithForms = renderer.RenderHtmlAsPdf(formHtml);
pdfWithForms.SaveAs("interactive-form.pdf");

Below is a table illustrating the different options available.

ClassChromePdfRenderer
DescriptionUsed to define PDF printout options, like paper size, DPI, headers, and footers
Properties / functionsTypeDescription
CustomCookiesDictionary<string, string>Custom cookies for the HTML render. Cookies do not persist between renders and must be set each time.
PaperFitVirtualPaperLayoutManagerA manager for setting up virtual paper layouts, controlling how content will be laid out on PDF "paper" pages. Includes options for Default Chrome Behavior, Zoomed, Responsive CSS3 Layouts, Scale-To-Page & Continuous Feed style PDF page setups.
UseMarginsOnHeaderAndFooterUseMarginsUse margin values from the main document when rendering headers and footers.
CreatePdfFormsFromHtmlboolTurns all HTML form elements into editable PDF forms. Default value is true.
CssMediaTypePdfCssMediaTypeEnables Media="screen" CSS Styles and StyleSheets. Default value is PdfCssMediaType.Screen.
CustomCssUrlstringAllows a custom CSS style-sheet to be applied to HTML before rendering. May be a local file path or a remote URL. Only applicable when rendering HTML to PDF.
EnableJavaScriptboolEnables JavaScript and JSON to be executed before the page is rendered. Ideal for printing from Ajax / Angular Applications. Default value is false.
EnableMathematicalLaTexboolEnables rendering of Mathematical LaTeX Elements.
JavascriptstringA custom JavaScript string to be executed after all HTML has loaded but before PDF rendering.
JavascriptMessageListenerStringDelegateA method callback to be invoked whenever a browser JavaScript console message becomes available.
FirstPageNumberintFirst page number to be used in PDF Headers and Footers. Default value is 1.
TableOfContentsTableOfContentsTypesGenerates a table of contents at the location in the HTML document where an element is found with id "IronPDF-toc".
GrayScaleboolOutputs a black-and-white PDF. Default value is false.
TextHeaderITextHeaderFooterSets the footer content for every PDF page as text, supporting 'mail-merge' and automatically turning URLs into hyperlinks.
TextFooter
HtmlHeaderHtmlHeaderFooterSets the header content for every PDF page as HTML. Supports 'mail-merge'.
HtmlFooter
InputEncodingEncodingThe input character encoding as a string. Default value is Encoding.UTF8.
MarginTopdoubleTop PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25.
MarginRightdoubleRight PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25.
MarginBottomdoubleBottom PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25.
MarginLeftdoubleLeft PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25.
PaperOrientationPdfPaperOrientationThe PDF paper orientation, such as Portrait or Landscape. Default value is Portrait.
PaperSizePdfPaperSizeSets the paper size
SetCustomPaperSizeinCentimetersdoubleSets the paper size in centimeters.
SetCustomPaperSizeInInchesSets the paper size in inches.
SetCustomPaperSizeinMilimetersSets the paper size in millimeters.
SetCustomPaperSizeinPixelsOrPointsSets the paper size in screen pixels or printer points.
PrintHtmlBackgroundsBooleanIndicates whether to print background colors and images from HTML. Default value is true.
RequestContextRequestContextsRequest context for this render, determining isolation of certain resources such as cookies.
TimeoutIntegerRender timeout in seconds. Default value is 60.
TitleStringPDF Document Name and Title metadata, useful for mail-merge and automatic file naming in the IronPDF MVC and Razor extensions.
ForcePaperSizeBooleanForce page sizes to be exactly what is specified via IronPdf.ChromePdfRenderOptions.PaperSize by resizing the page after generating a PDF from HTML. Helps correct small errors in page size when rendering HTML to PDF.
WaitForWaitForA wrapper object that holds configuration for wait-for mechanism for users to wait for certain events before rendering. By default, it will wait for nothing.

Ready to explore more capabilities? Visit our tutorial page: Convert PDFs

Frequently Asked Questions

What are the primary rendering options available in IronPDF?

IronPDF offers options like setting margins, headers, footers, paper size, and enabling JavaScript execution to control PDF generation and formatting from HTML.

How can I use IronPDF to create a PDF with no margins?

You can set the `MarginTop`, `MarginBottom`, `MarginLeft`, and `MarginRight` properties of the `ChromePdfRenderer` to zero to generate a PDF without margins using IronPDF.

Is it possible to generate a PDF with a custom paper size using IronPDF?

Yes, IronPDF allows you to specify custom paper sizes in millimeters, inches, centimeters, or pixels using the `SetCustomPaperSize` methods available in the `RenderingOptions`.

Can IronPDF render HTML content that includes JavaScript?

Certainly, IronPDF’s `EnableJavaScript` property in the `RenderingOptions` allows for JavaScript to execute before rendering the HTML to PDF.

How do advanced rendering options benefit professional document generation in IronPDF?

Advanced options like adding headers and footers, enabling JavaScript for dynamic content, configuring custom CSS, and setting precise margins enhance the customization for professional document outputs.

What is the function of the `PaperFit` option in IronPDF?

`PaperFit` in IronPDF’s `ChromePdfRenderer` controls content layout styles on PDF pages, providing options like responsive CSS3 layouts and continuous feed style setups.

How can IronPDF assist with rendering interactive PDF forms?

IronPDF automatically converts HTML form elements into interactive PDF forms when the `CreatePdfFormsFromHtml` property is set to true.

What is the significance of enabling `PrintHtmlBackgrounds` in IronPDF?

Enabling `PrintHtmlBackgrounds` ensures that all background colors and images defined in HTML are printed in the PDF, maintaining the visual integrity of the document.

Can IronPDF merge or split PDFs after applying rendering options?

Yes, IronPDF supports merging and splitting of PDF documents, which can be useful when combining or breaking down complex documents after rendering.

How does IronPDF handle dynamic web content rendering?

IronPDF handles dynamic web content by enabling JavaScript execution and allowing delays for JavaScript execution using the `WaitFor` class to ensure all interactive elements are fully rendered.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 20,756,830Version:2026.8just 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.8

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.8

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.

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 IronPDF
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