IRONSOFTWAREHOME

Rendering PDFs with Azure Blob Storage Images in C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

To render PDFs with Azure Blob Storage images in C#, retrieve the blob data as binary, convert it to a base64 string, embed it in an HTML img tag, and use IronPDF's ChromePdfRenderer to convert the HTML to PDF.

Azure Blob Storage is a cloud-based storage service provided by Microsoft Azure. It stores large amounts of unstructured data, such as text or binary data, accessible via HTTP or HTTPS. When working with PDFs in C#, IronPDF provides powerful capabilities for handling various image formats and sources, including those stored in cloud services like Azure Blob Storage.

To use images stored in Azure Blob Storage, you must handle the binary data format rather than direct file references. The solution is to convert images to base64 strings and embed them in img tags. This approach works seamlessly with IronPDF's HTML to PDF conversion features, maintaining image quality and formatting.

Quickstart: Render PDFs with Azure Blob Storage Images
  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    var blobBase64 = Convert.ToBase64String(new BlobContainerClient("conn","cont").GetBlobClient("img.jpg").DownloadContent().Value.Content.ToArray());
    new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf($"<img src=\"data:image/jpeg;base64,{blobBase64}\" />").SaveAs("blobImage.pdf");
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

How Do I Convert Azure Blob Images to HTML?

Set up an Azure Storage account with a container containing blobs, then handle authentication and connection in your C# project. Use the Azure.Storage.Blobs NuGet package alongside IronPDF. For complex authentication scenarios, explore IronPDF's HTTP request header capabilities for secured blob access.

Use the DownloadAsync method to download images as streams. Convert the stream data to Base64 and embed it in HTML img tags. Merge the htmlContent variable into your HTML document. This technique works well for creating reports or documents with dynamically loaded cloud storage images.

using Azure.Storage.Blobs;
using System;
using System.IO;
using System.Threading.Tasks;

public async Task ConvertBlobToHtmlAsync()
{
    // Define your connection string and container name
    string connectionString = "your_connection_string";
    string containerName = "your_container_name";

    // Initialize BlobServiceClient with the connection string
    BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

    // Get the BlobContainerClient for the specified container
    BlobContainerClient blobContainer = blobServiceClient.GetBlobContainerClient(containerName);

    // Get the reference to the blob and initialize a stream
    BlobClient blobClient = blobContainer.GetBlobClient("867.jpg");
    using var stream = new MemoryStream();

    // Download the blob data to the stream
    await blobClient.DownloadToAsync(stream);
    stream.Position = 0; // Reset stream position

    // Convert the stream to a byte array
    byte[] array = stream.ToArray();

    // Convert bytes to base64
    var base64 = Convert.ToBase64String(array);

    // Create an img tag with the base64-encoded string
    var imageTag = $"<img src=\"data:image/jpeg;base64,{base64}\"/><br/>";
    
    // Use the imageTag in your HTML document as needed
}

When working with multiple images or different formats, leverage IronPDF's support for various image types including JPG, PNG, SVG, and GIF. The base64 encoding method works universally across all these formats.

Working with Different Image Formats

Azure Blob Storage supports various image formats, and IronPDF handles them all when properly encoded. Here's an enhanced example that dynamically determines the MIME type:

public string GetImageMimeType(string blobName)
{
    var extension = Path.GetExtension(blobName).ToLower();
    return extension switch
    {
        ".jpg" or ".jpeg" => "image/jpeg",
        ".png" => "image/png",
        ".gif" => "image/gif",
        ".svg" => "image/svg+xml",
        ".webp" => "image/webp",
        _ => "image/jpeg" // default fallback
    };
}

public async Task<string> CreateImageTagFromBlob(BlobClient blobClient)
{
    using var stream = new MemoryStream();
    await blobClient.DownloadToAsync(stream);
    stream.Position = 0;
    
    var base64 = Convert.ToBase64String(stream.ToArray());
    var mimeType = GetImageMimeType(blobClient.Name);
    
    return $"<img src=\"data:{mimeType};base64,{base64}\" alt=\"{Path.GetFileNameWithoutExtension(blobClient.Name)}\"/>";
}

How Do I Convert the HTML to PDF?

Convert the htmlContent to PDF using the RenderHtmlAsPdf() method of ChromePdfRenderer. IronPDF's Chrome rendering engine maintains image quality and positioning during conversion. For optimal results, configure rendering options to control PDF output quality.

Here's how to call SaveAs():

using IronPdf;

// Instantiate Renderer
var renderer = new ChromePdfRenderer();

// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf(imageTag);

// Export to a file
pdf.SaveAs("imageToPdf.pdf");

Adjust the pdfOptions variable to include your actual HTML content with the bodyHtml.

Complete Working Example

Here's a comprehensive example combining Azure Blob Storage retrieval with IronPDF rendering, including error handling and optimization:

using Azure.Storage.Blobs;
using IronPdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

public class AzureBlobToPdfConverter
{
    private readonly string _connectionString;
    private readonly ChromePdfRenderer _renderer;

    public AzureBlobToPdfConverter(string connectionString)
    {
        _connectionString = connectionString;
        _renderer = new ChromePdfRenderer();
    }

    public async Task<PdfDocument> ConvertBlobImagesToPdfAsync(string containerName, List<string> blobNames)
    {
        var htmlBuilder = new StringBuilder();
        htmlBuilder.Append("<html><body style='margin: 20px;'>");
        
        var blobServiceClient = new BlobServiceClient(_connectionString);
        var containerClient = blobServiceClient.GetBlobContainerClient(containerName);

        foreach (var blobName in blobNames)
        {
            try
            {
                var blobClient = containerClient.GetBlobClient(blobName);
                var imageTag = await CreateImageTagFromBlob(blobClient);
                htmlBuilder.Append(imageTag);
                htmlBuilder.Append("<br/><br/>"); // Add spacing between images
            }
            catch (Exception ex)
            {
                // Log error and continue with other images
                Console.WriteLine($"Error processing blob {blobName}: {ex.Message}");
            }
        }

        htmlBuilder.Append("</body></html>");
        
        // Convert the complete HTML to PDF
        return _renderer.RenderHtmlAsPdf(htmlBuilder.ToString());
    }

    private async Task<string> CreateImageTagFromBlob(BlobClient blobClient)
    {
        using var stream = new MemoryStream();
        await blobClient.DownloadToAsync(stream);
        stream.Position = 0;
        
        var base64 = Convert.ToBase64String(stream.ToArray());
        var mimeType = GetImageMimeType(blobClient.Name);
        
        return $"<img src=\"data:{mimeType};base64,{base64}\" " +
               $"alt=\"{Path.GetFileNameWithoutExtension(blobClient.Name)}\" " +
               $"style=\"max-width: 100%; height: auto;\"/>";
    }

    private string GetImageMimeType(string blobName)
    {
        var extension = Path.GetExtension(blobName).ToLower();
        return extension switch
        {
            ".jpg" or ".jpeg" => "image/jpeg",
            ".png" => "image/png",
            ".gif" => "image/gif",
            ".svg" => "image/svg+xml",
            ".webp" => "image/webp",
            _ => "image/jpeg"
        };
    }
}
C#

Performance Considerations

When working with large images or multiple blobs, implement async and multithreading techniques to improve performance. Add caching mechanisms to avoid downloading the same blobs repeatedly.

For production environments, especially Azure deployments, review IronPDF's Azure deployment guide for best practices and configuration recommendations. For memory-intensive operations, use IronPDF's memory stream capabilities to optimize resource usage.

Security and Authentication

Ensure proper authentication when accessing Azure Blob Storage. For enhanced security, implement custom HTTP headers when accessing protected resources. Consider implementing PDF password protection for sensitive documents containing Azure blob images.

Troubleshooting Common Issues

If you encounter blob storage integration issues, consult IronPDF's Azure troubleshooting guide for solutions to common problems. For image-specific issues, the image rendering documentation provides detailed guidance on handling various scenarios.

DownloadToStreamAsync imageTag imageTag RenderHtmlAsPdf RenderHtmlAsPdf "htmlContent" imageTag

Frequently Asked Questions

How can IronPDF be used with Azure Blob Storage images in C#?

IronPDF can convert images stored in Azure Blob Storage to PDFs by retrieving blob data, converting it to base64 strings, embedding them in HTML `img` tags, and using the `ChromePdfRenderer` to render the HTML as a PDF.

What image formats does IronPDF support when used with Azure Blob Storage?

IronPDF supports various image formats such as JPG, PNG, SVG, and GIF when creating PDFs from Azure Blob Storage images. It utilizes base64 encoding for seamless integration.

What are the steps to create a PDF from Azure Blob images using IronPDF?

The steps include downloading IronPDF, retrieving blob data, converting it to base64, embedding it in HTML `img` tags, and rendering the HTML to PDF using IronPDF.

How does IronPDF maintain image quality during the PDF conversion from blob storage?

IronPDF leverages its Chrome rendering engine to maintain high image quality and formatting accuracy when converting HTML with embedded images to PDF.

Can IronPDF handle multiple images from Azure Blob Storage for PDF conversion?

Yes, IronPDF can process multiple images, generating a PDF with all images embedded, by programmatically creating HTML with multiple `img` tags, each representing a different image.

How does base64 encoding aid in using images from Azure Blob Storage with IronPDF?

Base64 encoding allows binary data to be converted into a text format. Images from Azure Blob Storage are encoded into base64, embedded in HTML, and rendered by IronPDF into a PDF.

What methods does IronPDF offer for image insertion within PDFs?

IronPDF provides features to embed images by rendering HTML content containing base64-encoded image data, supporting dynamic and versatile PDF document creation.

How can I enhance performance when generating PDFs with large Azure Blob Storage images using IronPDF?

Implement async processes and caching strategies to handle large images more efficiently. IronPDF supports techniques to reduce redundant downloads and optimize rendering time.

Is it possible to secure documents with Azure Blob images using IronPDF?

Yes, IronPDF allows setting PDF password protection for documents that include sensitive images retrieved from Azure Blob Storage, enhancing security and compliance.

What steps should be followed if encountering issues with Azure Blob and IronPDF?

Consult IronPDF's troubleshooting guides for blob storage integration issues. Common solutions involve verifying connection strings, blob path accuracy, and proper authentication.

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 20,878,335Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
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.

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