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#
- Install IronPDF via NuGet Package Manager
- Create a
ChromePdfRendererinstance - Configure rendering options through the
RenderingOptionsproperty - Render your content (HTML, Markdown, etc.) to PDF
- Save the resulting PDF document
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
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");Deploy to test on your live environment
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.
Minimal Workflow (5 steps)
- Download the C# library to use rendering options
- Prepare the HTML assets or file for PDF conversion
- Instantiate the `ChromePdfRenderer` class
- Access the `RenderingOptions` property to configure settings
- Render the PDF in the desired format
## 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. ```csharp :path=/static-assets/pdf/content-code-examples/how-to/rendering-options-render.cs ```### 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](https://ironpdf.com/how-to/headers-and-footers/) or work with [custom paper sizes](https://ironpdf.com/how-to/custom-paper-size/): ```csharp 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 = @"
This document demonstrates advanced rendering options.
## 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: ```csharp using IronPdf; var renderer = new ChromePdfRenderer(); // Enable PDF form creation from HTML forms renderer.RenderingOptions.CreatePdfFormsFromHtml = true; // HTML with form elements string formHtml = @""; PdfDocument pdfWithForms = renderer.RenderHtmlAsPdf(formHtml); pdfWithForms.SaveAs("interactive-form.pdf"); ``` Below is a table illustrating the different options available.
| Class | ChromePdfRenderer | |
|---|---|---|
| Description | Used to define PDF printout options, like paper size, DPI, headers, and footers | |
| Properties / functions | Type | Description |
| `CustomCookies` | `Dictionary<string, string>` | Custom cookies for the HTML render. Cookies do not persist between renders and must be set each time. |
| `PaperFit` | `VirtualPaperLayoutManager` | A 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. |
| `UseMarginsOnHeaderAndFooter` | `UseMargins` | Use margin values from the main document when rendering headers and footers. |
| `CreatePdfFormsFromHtml` | `bool` | Turns all HTML form elements into editable PDF forms. Default value is true. |
| `CssMediaType` | `PdfCssMediaType` | Enables Media="screen" CSS Styles and StyleSheets. Default value is PdfCssMediaType.Screen. |
| `CustomCssUrl` | `string` | Allows 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. |
| `EnableJavaScript` | `bool` | Enables JavaScript and JSON to be executed before the page is rendered. Ideal for printing from Ajax / Angular Applications. Default value is false. |
| `EnableMathematicalLaTex` | `bool` | Enables rendering of Mathematical LaTeX Elements. |
| `Javascript` | `string` | A custom JavaScript string to be executed after all HTML has loaded but before PDF rendering. |
| `JavascriptMessageListener` | `StringDelegate` | A method callback to be invoked whenever a browser JavaScript console message becomes available. |
| `FirstPageNumber` | `int` | First page number to be used in PDF Headers and Footers. Default value is 1. |
| `TableOfContents` | `TableOfContentsTypes` | Generates a table of contents at the location in the HTML document where an element is found with id "ironpdf-toc". |
| `GrayScale` | `bool` | Outputs a black-and-white PDF. Default value is false. |
| `TextHeader` | `ITextHeaderFooter` | Sets the footer content for every PDF page as text, supporting 'mail-merge' and automatically turning URLs into hyperlinks. |
| `TextFooter` | ||
| `HtmlHeader` | `HtmlHeaderFooter` | Sets the header content for every PDF page as HTML. Supports 'mail-merge'. |
| `HtmlFooter` | ||
| `InputEncoding` | `Encoding` | The input character encoding as a string. Default value is Encoding.UTF8. |
| `MarginTop` | `double` | Top PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25. |
| `MarginRight` | `double` | Right PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25. |
| `MarginBottom` | `double` | Bottom PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25. |
| `MarginLeft` | `double` | Left PDF "paper" margin in millimeters. Set to zero for border-less and commercial printing applications. Default value is 25. |
| `PaperOrientation` | `PdfPaperOrientation` | The PDF paper orientation, such as Portrait or Landscape. Default value is Portrait. |
| `PaperSize` | `PdfPaperSize` | Sets the paper size |
| `SetCustomPaperSizeinCentimeters` | `double` | Sets the paper size in centimeters. |
| `SetCustomPaperSizeInInches` | Sets the paper size in inches. | |
| `SetCustomPaperSizeinMilimeters` | Sets the paper size in millimeters. | |
| `SetCustomPaperSizeinPixelsOrPoints` | Sets the paper size in screen pixels or printer points. | |
| `PrintHtmlBackgrounds` | `Boolean` | Indicates whether to print background colors and images from HTML. Default value is true. |
| `RequestContext` | `RequestContexts` | Request context for this render, determining isolation of certain resources such as cookies. |
| `Timeout` | `Integer` | Render timeout in seconds. Default value is 60. |
| `Title` | `String` | PDF Document Name and Title metadata, useful for mail-merge and automatic file naming in the IronPdf MVC and Razor extensions. |
| `ForcePaperSize` | `Boolean` | Force 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. |
| `WaitFor` | `WaitFor` | A 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. |
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.






