Pixel Perfect HTML Formatting

To make your PDFs look perfect, You'll need to develop excellent HTML templates or work with a web dev to do it for you.

1. Debug and Test your HTML

You can debug your HTML, CSS and JS in your Chrome or 'a similar' desktop browser. Then, when you know it works perfectly - connect it to IronPDF, and it will look identical to the way it looks in Chrome.

Basic Use

This code example will render PDFs that are pixel perfect to the latest Chrome desktop browser.

ChromePdfRenderer Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.PrintHtmlBackgrounds = true;
ChromePdfRenderer Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.PrintHtmlBackgrounds = true;
Dim Renderer As New ChromePdfRenderer()
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
Renderer.RenderingOptions.PrintHtmlBackgrounds = True
VB   C#

Advanced Html Development

Advanced Chrome user developers can match with 100% precision, by using IronPDFs default settings and enabling "Emulate CSS media > Screen" https://developer.chrome.com/docs/devtools/css/print-preview/

ChromePdfRenderer Renderer = new ChromePdfRenderer(); 
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen; 
Renderer.RenderingOptions.PrintHtmlBackgrounds = true;
ChromePdfRenderer Renderer = new ChromePdfRenderer(); 
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen; 
Renderer.RenderingOptions.PrintHtmlBackgrounds = true;
Dim Renderer As New ChromePdfRenderer()
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen
Renderer.RenderingOptions.PrintHtmlBackgrounds = True
VB   C#

Repeating Table Headers

If you have a HTML containing a table that will span more than once page, you probably would like Table Headers to repeat perfectly on each PDF page.

  • In this case, you can only use the Print CssMediaType.
  • Using Screen instructs Chrome to print the headers only once.
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
VB   C#

2. Set Render Delay and Render Timeout appropriately

IronPDF's default rendering timeout is 30 seconds. Anything taking longer to process will not render without further instruction. To override the default setting setting, adjust the RenderingOptions.Timeout.

Not setting a timeout or having a render delay longer than the set timeout will produce "Unable to Render PDF" Exception

RenderingOptions.Timeout = 60; // seconds
RenderingOptions.RenderDelay = 30000; //milliseconds
RenderingOptions.Timeout = 60; // seconds
RenderingOptions.RenderDelay = 30000; //milliseconds
RenderingOptions.Timeout = 60 ' seconds
RenderingOptions.RenderDelay = 30000 'milliseconds
VB   C#
API Reference:

3. To compare the result, open your HTML in the Chrome desktop web browser

Note: Export any HTML string and assets to stand alone HTML files and edit them manually, or ask a friendly web developer to help.

4. Open the Print Preview window (Ctrl+P on Windows)

You may need to change the paper size and enable printing background images in the Chrome Print dialog.

5. Select the Save as PDF option

Once Print to PDF in Chrome is perfect - IronPDF will match it

6. Now the HTML is perfect, run it though IronPDF

Now the HTML is perfect, run it through IronPDF and it will look identical. Use {PlaceHolders} to merge in customer data. The code examples at https://ironpdf.com/examples/using-html-to-create-a-pdf/ will really help!

If this tutorial does not help to resolve your issue, then please Contact Engineering Support and we will adapt and improve our documentation to assist you further.

.Net Software Engineer For many this is the most efficient way to generate PDF files from .Net, because there is no additional API to learn, or complex design system to navigate

Jean Ashberg

.Net Software Engineer

Jean is an independent software developer for corporate internal information solutions based in Massachusetts, USA.

Jean was an early adopter of IronPDF, and has repeatedly been involved in ‘speccing-out’ product improvement and building a roadmap to creating a single stable library for C# that covers all major PDF product feature use cases.