Image Header or Footer Without Inflating PDF Size
Adding a Base64 logo to every page can balloon the output file, because the image gets re-embedded on each page. Split the header or footer into a static image layer and a dynamic text layer so the image is embedded once while per-page content stays small.
Solution
1. Split the Header or Footer Into Two HTML Fragments
Put the image, and any text that never changes, in a static fragment. Place per-page content such as {page} in a dynamic fragment. Give both fragments the same table layout with matching cell widths, so the dynamic text lands in the correct position over the static layer.
2. Add the Static Fragment First
Call AddHtmlHeadersAndFooters with only the static fragment. The Base64 image is rendered and embedded once.
3. Add the Dynamic Fragment in a Second Pass
Call AddHtmlHeadersAndFooters again with only the dynamic fragment. This pass contains no image, so the per-page content stays small. Rendering the static and dynamic parts together makes the engine treat all of the HTML as dynamic and re-embed the image on every page, which is what causes the file to grow.
using IronPdf;
var pdf = PdfDocument.FromFile("input.pdf");
// Static layer: holds the Base64 image. The page-number cell is left empty.
string staticFooter = @"
<table style='width:100%; table-layout:fixed;'>
<tr>
<td style='width:20%;'>
<img src='data:image/png;base64,iVBORw0KGg...' style='width:150px;' />
</td>
<td style='width:80%; text-align:right;'></td>
</tr>
</table>";
// Dynamic layer: holds only {page}. Same layout, but no image.
string dynamicFooter = $@"
<table style='width:100%; table-layout:fixed;'>
<tr>
<td style='width:20%;'></td>
<td style='width:80%; text-align:right; font-size:10px;'>Page {{page}} of {pdf.PageCount}</td>
</tr>
</table>";
// Pass 1: add the static image footer (image embedded once).
pdf.AddHtmlHeadersAndFooters(new ChromePdfRenderOptions
{
HtmlFooter = new HtmlHeaderFooter { HtmlFragment = staticFooter, MaxHeight = 40 }
});
// Pass 2: add the dynamic page-number footer (no image, stays small).
pdf.AddHtmlHeadersAndFooters(new ChromePdfRenderOptions
{
HtmlFooter = new HtmlHeaderFooter { HtmlFragment = dynamicFooter, MaxHeight = 40 }
});
pdf.SaveAs("output.pdf");
The two passes share an identical table-layout:fixed structure with the same cell widths, so the page number in the dynamic layer aligns with the empty cell reserved for it in the static layer.
4. (Optional) Reference an External Image or SVG
If you do not need the image inlined as Base64, point at an external image file or use an SVG instead. Either option can reduce the output size further than a Base64 string.
Notes
- The same technique applies to headers: keep the image in the static pass and place any dynamic header text in the second pass.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.