HTML Rendering Settings

IronPDF aims to be as flexible as possible for the developer.

In this C# PDF Generation Tutorial Example, we show the balance between providing an API that automates internal functionality and providing one that gives you control.

IronPDF supports many customizations for generated PDF files, including page sizing, page margins, header/footer content, content scaling, CSS rulesets, and JavaScript execution.


We want developers to be able to control how Chrome turns a web page into a PDF. The ChromePdfRenderer Class Overview makes this possible.

Examples of settings available on the ChromePdfRenderer class include settings for margins, headers, footers, paper size, and form creation.

// Import the necessary namespaces for IronPDF
using IronPdf;

namespace PdfGenerationExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of the ChromePdfRenderer class
            var Renderer = new ChromePdfRenderer();

            // Customize the rendering options
            Renderer.RenderingOptions = new ChromePdfRenderOptions()
            {
                // Set paper size to A4
                PaperSize = PdfPaperSize.A4,

                // Set a margin of 10mm on all sides
                MarginTop = 10, // in millimeters
                MarginBottom = 10, // in millimeters
                MarginLeft = 10, // in millimeters
                MarginRight = 10, // in millimeters

                // Enable header and footer
                DisplayHeader = true,
                DisplayFooter = true,

                // Set headers and footers content
                Header = new HtmlHeaderFooter()
                {
                    HtmlFragment = "<p>This is the header</p>",
                    Height = 15 // in millimeters
                },
                Footer = new HtmlHeaderFooter()
                {
                    HtmlFragment = "<p>This is the footer</p>",
                    Height = 15 // in millimeters
                }
            };

            // Render a URL to a PDF document
            var pdfDocument = Renderer.RenderUrlAsPdf("https://yourwebsite.com");

            // Save the PDF document to a file
            pdfDocument.SaveAs("output.pdf");
        }
    }
}
// Import the necessary namespaces for IronPDF
using IronPdf;

namespace PdfGenerationExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of the ChromePdfRenderer class
            var Renderer = new ChromePdfRenderer();

            // Customize the rendering options
            Renderer.RenderingOptions = new ChromePdfRenderOptions()
            {
                // Set paper size to A4
                PaperSize = PdfPaperSize.A4,

                // Set a margin of 10mm on all sides
                MarginTop = 10, // in millimeters
                MarginBottom = 10, // in millimeters
                MarginLeft = 10, // in millimeters
                MarginRight = 10, // in millimeters

                // Enable header and footer
                DisplayHeader = true,
                DisplayFooter = true,

                // Set headers and footers content
                Header = new HtmlHeaderFooter()
                {
                    HtmlFragment = "<p>This is the header</p>",
                    Height = 15 // in millimeters
                },
                Footer = new HtmlHeaderFooter()
                {
                    HtmlFragment = "<p>This is the footer</p>",
                    Height = 15 // in millimeters
                }
            };

            // Render a URL to a PDF document
            var pdfDocument = Renderer.RenderUrlAsPdf("https://yourwebsite.com");

            // Save the PDF document to a file
            pdfDocument.SaveAs("output.pdf");
        }
    }
}
' Import the necessary namespaces for IronPDF
Imports IronPdf

Namespace PdfGenerationExample
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			' Create an instance of the ChromePdfRenderer class
			Dim Renderer = New ChromePdfRenderer()

			' Customize the rendering options
			Renderer.RenderingOptions = New ChromePdfRenderOptions() With {
				.PaperSize = PdfPaperSize.A4,
				.MarginTop = 10,
				.MarginBottom = 10,
				.MarginLeft = 10,
				.MarginRight = 10,
				.DisplayHeader = True,
				.DisplayFooter = True,
				.Header = New HtmlHeaderFooter() With {
					.HtmlFragment = "<p>This is the header</p>",
					.Height = 15
				},
				.Footer = New HtmlHeaderFooter() With {
					.HtmlFragment = "<p>This is the footer</p>",
					.Height = 15
				}
			}

			' Render a URL to a PDF document
			Dim pdfDocument = Renderer.RenderUrlAsPdf("https://yourwebsite.com")

			' Save the PDF document to a file
			pdfDocument.SaveAs("output.pdf")
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel
  • The code example above demonstrates how to create a PDF document from a web page using the IronPDF library.
  • This involves setting up a renderer with specific options like paper size, margins, header, and footer.
  • The ChromePdfRenderer class is used to render the URL to a PDF.
  • The resulting PDF document is then saved to a file named "output.pdf".