Pixel Perfect HTML Formatting

To make your PDFs look perfect, you'll need to develop excellent HTML templates or work with a web developer to do it for you. This troubleshooting article is taken from a full tutorial on Debugging Your HTML.

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;

Advanced HTML Development

Advanced Chrome user developers can achieve 100% precision by using IronPDF's 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;

2. Compare the Result

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 web developer to help

3. 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.

4. Select the 'Save as PDF' Option

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

5. Run 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.