IRONSOFTWAREHOME

Image Header or Footer Without Inflating PDF Size

Curtis Chau
Curtis Chau
Updated: August 21, 2026

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

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");
C#

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.

Warning: Both fragments must share the same table structure and cell widths, or the dynamic text such as the page number will not line up over 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
Technical Writer

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.

...
Read More

Ready to Get Started?

Nuget Downloads 21,228,841Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999