How to Use Rendering Options in IronPDF with C#

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

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy 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>" }, Language = "en-US", Timeout = 120000 } }
        .RenderHtmlStringAsPdf("<h1>Hello Options</h1>")
        .SaveAs("renderingOptions.pdf");
  3. Deploy 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.

:path=/static-assets/pdf/content-code-examples/how-to/rendering-options-render.cs
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");
Imports IronPdf

' Instantiate a ChromePdfRenderer object, which uses a headless version of the Chrome browser
' to render HTML/CSS as a PDF document.
Private renderer As 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 With {.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.
Dim md As String = "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.
Dim pdf As PdfDocument = renderer.RenderMarkdownStringAsPdf(md)

' Save the generated PDF to a file named "renderingOptions.pdf."
pdf.SaveAs("renderingOptions.pdf")
$vbLabelText   $csharpLabel

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.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");
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.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");
Imports IronPdf
Imports IronPdf.Rendering

' Create renderer with advanced options
Dim 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.RenderDelay = 2000 ' Wait 2 seconds for JS to execute

' Add professional header with page numbers
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
    .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 With {
    .Height = 20,
    .HtmlFragment = "<div style='text-align: center; font-size: 10px;'>
                     Generated on {date} at {time}
                     </div>"
}

' Render HTML content
Dim htmlContent As String = "
<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>"

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("professional-document.pdf")
$vbLabelText   $csharpLabel

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");
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");
Imports IronPdf

Dim renderer = New ChromePdfRenderer()

' Enable PDF form creation from HTML forms
renderer.RenderingOptions.CreatePdfFormsFromHtml = True

' HTML with form elements
Dim formHtml As String = "
<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>"

Dim pdfWithForms As PdfDocument = renderer.RenderHtmlAsPdf(formHtml)
pdfWithForms.SaveAs("interactive-form.pdf")
$vbLabelText   $csharpLabel

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
CustomCookiesDictionarCustom 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 rendering options in PDF generation?

Rendering options in IronPDF are settings that control how PDF documents are created, displayed, and printed through the ChromePdfRenderer class. They include configurations for margins, headers, footers, paper size, JavaScript execution, CSS media types, form elements, and tables of contents, allowing precise customization of PDF output from HTML, CSS, and other content sources.

How do I apply rendering options to a PDF?

To apply rendering options in IronPDF: 1) Install IronPDF via NuGet, 2) Create a ChromePdfRenderer instance, 3) Configure settings through the RenderingOptions property, 4) Render your content (HTML, Markdown, etc.) to PDF, and 5) Save the resulting PDF. You can set multiple options in a single line, such as margins, CSS media type, headers, and timeout values.

Can I use rendering options with non-HTML content?

Yes, while many rendering option properties are designed for HTML-to-PDF conversion, they work with other PDF conversion types in IronPDF too. You can apply rendering options when converting Markdown to PDF or other supported formats, giving you the same level of control over the final PDF output regardless of the source content type.

What is PaperFit and how does it work?

PaperFit is a manager within IronPDF's ChromePdfRenderer class that controls content layout on PDF pages. It offers different styles for rendering, including responsive CSS3 layouts or continuous feed options, helping ensure your content fits properly on the PDF pages according to your specific requirements.

Why should I configure rendering options for my PDFs?

Configuring rendering options in IronPDF ensures your PDFs generate with exact specifications needed for professional documents. This includes custom paper sizes, specific margins, headers and footers, or enabled JavaScript for dynamic content. This level of control is crucial when creating reports, invoices, or any documents requiring precise formatting.

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 17,269,395 | Version: 2026.1 just released