DEV Community

IronSoftware
IronSoftware

Posted on

Image to PDF in C# (.NET 10 Guide)

Converting images to PDF enables document workflows — scanning receipts into expense reports, archiving photos as PDFs for long-term storage, combining diagrams into technical documentation, bundling screenshots into bug reports. I've built systems converting scanned invoices to searchable PDFs, photo galleries to printable albums, engineering diagrams to specification documents.

The problem is that image-to-PDF conversion libraries often complicate simple tasks. iTextSharp requires instantiating Document objects, managing page sizes, calling Image.GetInstance(), calculating positioning coordinates, adding images to documents, closing streams. Stack Overflow answers show 20+ lines for converting a single JPG to PDF — creating documents, managing writers, calculating image dimensions, disposing resources properly.

IronPDF reduces this to one line: ImageToPdfConverter.ImageToPdf("image.jpg"). No page size calculations, no positioning math, no stream management. The library handles image dimensions, PDF page sizing, aspect ratio preservation automatically.

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var pdf = ImageToPdfConverter.ImageToPdf("receipt.jpg");
pdf.SaveAs("receipt.pdf");
Enter fullscreen mode Exit fullscreen mode

This converts a JPEG image to PDF. The PDF page size matches image dimensions automatically. Aspect ratio is preserved. No configuration required for basic conversion.

What NuGet Packages Do I Need?

Install IronPDF via Package Manager Console:

Install-Package IronPdf
Enter fullscreen mode Exit fullscreen mode

Or .NET CLI:

dotnet add package IronPdf
Enter fullscreen mode Exit fullscreen mode

IronPDF handles image formats natively — JPG, PNG, BMP, GIF, SVG, TIFF, WEBP all supported without additional libraries.

How Do I Convert Multiple Images to One PDF?

Combine multiple images into a single multi-page PDF:

var images = new[]
{
    "page1.jpg",
    "page2.jpg",
    "page3.jpg"
};

var pdf = ImageToPdfConverter.ImageToPdf(images);
pdf.SaveAs("document.pdf");
Enter fullscreen mode Exit fullscreen mode

Each image becomes a separate page. Page 1 contains page1.jpg, page 2 contains page2.jpg, etc. This is perfect for scanned documents where each page is a separate image file.

For dynamic image lists (unknown count at compile time):

var imageFiles = Directory.GetFiles("scans/", "*.png");
var pdf = ImageToPdfConverter.ImageToPdf(imageFiles);
pdf.SaveAs("scanned-document.pdf");
Enter fullscreen mode Exit fullscreen mode

This loads all PNG files from a directory, converts to a single PDF with one page per image.

I've processed document archives this way — scanning hundreds of paper contracts, each page saved as PNG, then combining into multi-page PDFs matching original documents.

What Image Formats Are Supported?

IronPDF handles common and specialized formats:

  • JPEG/JPG: Photos, scanned documents
  • PNG: Screenshots, diagrams with transparency
  • BMP: Windows bitmap format
  • GIF: Animations (first frame extracted)
  • SVG: Vector graphics (rendered at high quality)
  • TIFF: Multi-page scans (each page becomes PDF page)
  • WEBP: Modern compressed format

SVG support is particularly useful — vector images scale without pixelation. Engineering diagrams, logos, icons convert to crisp PDFs at any size.

TIFF multi-page support handles scanner output directly — many scanners save multi-page scans as single TIFF files with multiple frames. IronPDF automatically extracts all frames into PDF pages:

// multipage-scan.tiff contains 10 pages
var pdf = ImageToPdfConverter.ImageToPdf("multipage-scan.tiff");
// PDF now has 10 pages
Enter fullscreen mode Exit fullscreen mode

How Does Image Positioning Work?

By default, images center on PDF pages matching image dimensions. Customize with ImageBehavior options:

var pdf = ImageToPdfConverter.ImageToPdf("photo.jpg");
Enter fullscreen mode Exit fullscreen mode

Default behavior:

  • Page size matches image dimensions
  • Image centers on page
  • Aspect ratio preserved
  • No cropping

For specific layouts, IronPDF uses an HTML-based approach under the hood. The ImageToPdfConverter is a convenience wrapper around HTML rendering:

var renderer = new [ChromePdfRenderer](https://ironpdf.com/blog/videos/how-to-render-html-string-to-pdf-in-csharp-ironpdf/)();

var html = $@"
<!DOCTYPE html>
<html>
<body style='margin: 0; padding: 0;'>
    <img src='diagram.svg' style='width: 100%; height: 100%; object-fit: contain;' />
</body>
</html>
";

renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginBottom = 20;

var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("diagram-with-margins.pdf");
Enter fullscreen mode Exit fullscreen mode

This gives full control: CSS object-fit for scaling (contain, cover, fill), margins, positioning, multiple images per page.

I use HTML rendering for complex layouts — product catalogs with multiple images per page, annotated diagrams with labels, photo albums with captions.

How Does IronPDF Compare to iTextSharp for Images?

iTextSharp requires verbose setup:

// iTextSharp approach (complex)
using (var document = new Document())
using (var stream = new FileStream("output.pdf", FileMode.Create))
{
    PdfWriter.GetInstance(document, stream);
    document.Open();

    var image = iTextSharp.text.Image.GetInstance("photo.jpg");
    image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
    image.SetAbsolutePosition(0, 0);
    document.Add(image);

    document.Close();
}
Enter fullscreen mode Exit fullscreen mode

This is 12+ lines for one image. You manage document lifecycle (Open(), Close()), calculate scaling (ScaleToFit), position images (SetAbsolutePosition).

IronPDF is 2 lines:

var pdf = ImageToPdfConverter.ImageToPdf("photo.jpg");
pdf.SaveAs("output.pdf");
Enter fullscreen mode Exit fullscreen mode

The library calculates page size, handles scaling, manages resources automatically.

I migrated a medical imaging system from iTextSharp to IronPDF specifically because developers struggled with iTextSharp's positioning math. X-ray images needed precise sizing — iTextSharp required manual calculations for each image dimension. IronPDF's automatic fitting eliminated calculation errors.

Can I Add Metadata or Properties to Image PDFs?

Yes, set PDF metadata after conversion:

var pdf = ImageToPdfConverter.ImageToPdf("document-scan.jpg");

pdf.MetaData.Title = "Contract - Smith & Co";
pdf.MetaData.Author = "Legal Department";
pdf.MetaData.Keywords = "contract, signed, 2025";
pdf.MetaData.CreationDate = DateTime.Now;

pdf.SaveAs("contract.pdf");
Enter fullscreen mode Exit fullscreen mode

This adds searchable metadata helping document management systems index and organize PDFs.

For scanned archives, I add metadata programmatically based on filenames:

var files = Directory.GetFiles("contracts/");
foreach (var file in files)
{
    var pdf = ImageToPdfConverter.ImageToPdf(file);
    var fileName = Path.GetFileNameWithoutExtension(file);

    pdf.MetaData.Title = fileName;
    pdf.MetaData.Keywords = "scanned, contract, archive";

    pdf.SaveAs($"processed/{fileName}.pdf");
}
Enter fullscreen mode Exit fullscreen mode

How Do I Handle Very Large Images?

Large images (high-resolution scans, gigapixel photos) load entirely into memory during conversion. For batch processing hundreds of large images, process sequentially rather than loading all simultaneously:

var imageFiles = Directory.GetFiles("high-res-scans/");

foreach (var file in imageFiles)
{
    var pdf = ImageToPdfConverter.ImageToPdf(file);
    pdf.SaveAs($"pdfs/{Path.GetFileNameWithoutExtension(file)}.pdf");

    // PDF saved, memory freed before next image
}
Enter fullscreen mode Exit fullscreen mode

This processes one image at a time, releasing memory between conversions.

For truly massive images (100+ megapixels), consider downscaling before PDF conversion if print quality permits. PDF viewers struggle rendering gigapixel images anyway.

I've processed satellite imagery this way — downscaling 200 MP images to 20 MP before PDF conversion reduced file sizes 90% with no visible quality loss at print resolutions.

What About OCR for Scanned Images?

ImageToPdfConverter creates image-only PDFs — text isn't searchable. For searchable PDFs from scanned documents, use OCR (Optical Character Recognition):

// Image-only PDF (not searchable)
var imagePdf = ImageToPdfConverter.ImageToPdf("scan.jpg");

// For searchable text, use IronOCR (separate product)
// var ocr = new IronTesseract();
// var ocrResult = ocr.Read("scan.jpg");
// var searchablePdf = ocrResult.SaveAsPdf("searchable.pdf");
Enter fullscreen mode Exit fullscreen mode

IronOCR is a separate library for OCR functionality. For simple image archival without text search requirements, ImageToPdfConverter suffices.

Quick Reference

Scenario Code Use Case
Single image ImageToPdfConverter.ImageToPdf("img.jpg") Basic conversion
Multiple images ImageToPdfConverter.ImageToPdf(new[] {"1.jpg", "2.jpg"}) Multi-page PDF
Directory batch ImageToPdfConverter.ImageToPdf(Directory.GetFiles("*.png")) Batch conversion
SVG to PDF ImageToPdfConverter.ImageToPdf("logo.svg") Vector graphics
Multi-page TIFF ImageToPdfConverter.ImageToPdf("scan.tiff") Scanner output
With metadata Set pdf.MetaData properties after conversion Searchable archives
Custom layout Use ChromePdfRenderer with HTML <img> tags Complex layouts

Key Principles:

  • One-line conversion: ImageToPdfConverter.ImageToPdf(path) handles everything
  • Supports JPG, PNG, BMP, GIF, SVG, TIFF, WEBP formats
  • Multiple images create multi-page PDFs automatically
  • Page size matches image dimensions by default
  • Aspect ratio always preserved (no distortion)
  • IronPDF dramatically simpler than iTextSharp's manual image positioning
  • Process large image batches sequentially to manage memory
  • For searchable text, combine with IronOCR (separate product)
  • Under the hood uses HTML rendering — can access via ChromePdfRenderer for advanced layouts

The complete image to PDF guide includes examples for custom sizing, watermarks, and batch processing optimization.


Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.

Top comments (0)