How to Use the Rendering Options

Rendering options in PDF generation refer to the settings and configurations that determine how a PDF document is created, displayed, and printed. These options can include a wide range of settings, such as rendering form field elements, enabling JavaScript, generating a table of contents, adding headers and footers, adjusting margins, setting PDF paper size, and more.

The ChromePdfRenderer class in IronPDF provides various rendering options that allow users to customize how PDFs are generated. It includes PaperFit, a manager that controls how content is laid out on PDF pages, offering different layout styles such as responsive CSS3 layouts or continuous feed.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet

    PM > Install-Package IronPdf

  2. Copy the code

    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

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer



Rendering Options Example

Despite many rendering option properties being specifically designed for HTML-to-PDF conversion, they can also be used in other types of PDF conversions. Let's render Markdown syntax to PDF and use the rendering options to configure the PDF output.

: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

All Rendering Options

We have some advanced options that define PDF-rendering options like adjusting margins, paper orientation, paper size, and more.

Below is a table to illustrate the many different options.

ClassChromePdfRenderer
DescriptionUsed to define PDF printout options, like paper size, DPI, headers, and footers
Properties / functionsTypeDescription
CustomCookiesDictionaryCustom 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 see what else you can do? Check out our tutorial page here: Convert PDFs

Frequently Asked Questions

How can I optimize PDF rendering using IronPDF?

To optimize PDF rendering with IronPDF, leverage the RenderingOptions property of the ChromePdfRenderer class. This allows you to customize settings such as JavaScript execution, form field rendering, and custom paper sizes.

What is the role of the ChromePdfRenderer class in PDF generation?

The ChromePdfRenderer class in IronPDF is integral for PDF generation as it provides various rendering options to tailor how PDFs are created. It supports features like paper size adjustment, layout management, and JavaScript execution.

Can I generate PDFs from Markdown syntax with IronPDF?

Yes, IronPDF supports rendering options that allow you to convert Markdown syntax into PDFs. This can be achieved by configuring the ChromePdfRenderer class to handle Markdown input.

How do I adjust margins and headers in IronPDF?

Adjust margins and headers in IronPDF by utilizing the RenderingOptions property within the ChromePdfRenderer class. This allows you to specify custom margins and add headers and footers to your PDF documents.

Is it possible to enable grayscale output in PDF rendering?

Yes, IronPDF allows for grayscale output by configuring the RenderingOptions property. This option helps in reducing file size and is useful for print-friendly PDF generation.

How can I manage paper layout styles in IronPDF?

In IronPDF, you can manage paper layout styles using the PaperFit manager within the ChromePdfRenderer class. This provides options like Responsive CSS3 Layouts and Continuous Feed style setups.

What options are available for customizing paper size in IronPDF?

IronPDF offers methods such as SetCustomPaperSizeinCentimeters, SetCustomPaperSizeInInches, and SetCustomPaperSizeinMilimeters to define custom paper sizes for PDF documents.

How do I incorporate custom CSS when generating PDFs?

To incorporate custom CSS in PDF generation with IronPDF, use the CustomCssUrl property to specify a path to your CSS file. This ensures that your styles are applied during the rendering process.

Can IronPDF create fillable PDF forms from HTML input forms?

Yes, IronPDF can create fillable PDF forms from HTML input by enabling the CreatePdfFormsFromHtml property in the RenderingOptions. This feature is useful for developing interactive PDFs.

How can I troubleshoot JavaScript issues in PDF rendering?

Ensure that JavaScript is enabled by setting the EnableJavaScript property to true in the RenderingOptions of the ChromePdfRenderer class. This allows scripts to run during the PDF conversion process.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.