Embedding Bitmaps and Images
using IronPdf;
using IronSoftware.Drawing;
using System;
using System.IO;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Import image file as byte
byte[] binaryData = File.ReadAllBytes("sample.jpg");

// Convert byte to base64
string imgDataUri = @"data:image/jpg;base64," + Convert.ToBase64String(binaryData);
string imgHtml = $"<img src='{imgDataUri}'>";

PdfDocument pdf = renderer.RenderHtmlAsPdf(imgHtml);
pdf.SaveAs("embedded_example_1.pdf");
NuGet Download
PM > Install-Package IronPdf
Embedding Bitmaps and Images

Embedding Bitmaps and Images

When you want to embed an image in HTML using Base64 encoding, you need to acquire the binary data of the image either by reading the image file or receiving it through a network request. In this example, we have imported the image we want to use and acquired its binary data. Then, using the Convert.ToBase64String method, you successfully converted it to Base64. Through this method, you will be able to add your images to any HTML content that you are using to render PDF documents.

For a more comprehensive guide, including additional examples and sample code, visit this How-to Guide.

Explore Data URI Schemes for Embedding Images in PDFs
View on GitHub

Ready to Get Started?

Nuget Downloads 21,739,885Version:2026.10just released