Images To PDF

Construct a PDF from Image Files Using the IronPdf.ImageToPdfConverter Class

How to Convert an Image to a PDF in C#

Given a single image located on a computer at C:\images\example.png, you can quickly convert it into a PDF document by calling the IronPdf.ImageToPdfConverter.ImageToPdf method with its file path:

// Convert a single image to a PDF.
var pdf = IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png");
// Save the resulting PDF to the specified location.
pdf.SaveAs("example.pdf");
// Convert a single image to a PDF.
var pdf = IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png");
// Save the resulting PDF to the specified location.
pdf.SaveAs("example.pdf");
' Convert a single image to a PDF.
Dim pdf = IronPdf.ImageToPdfConverter.ImageToPdf("C:\images\example.png")
' Save the resulting PDF to the specified location.
pdf.SaveAs("example.pdf")
$vbLabelText   $csharpLabel

Combine Multiple Images Into a PDF File

You can also convert multiple images into a single PDF document using System.IO.Directory.EnumerateFiles along with ImageToPdfConverter.ImageToPdf:

// Define the source directory containing the images.
string sourceDirectory = @"D:\web\assets";
// Define the path for the resulting PDF.
string destinationFile = "JpgToPDF.pdf";

// Get all image files in the source directory with a .jpg extension.
var imageFiles = System.IO.Directory.EnumerateFiles(sourceDirectory, "*.jpg");

// Convert the images into a single PDF.
var pdf = IronPdf.ImageToPdfConverter.ImageToPdf(imageFiles);

// Save the resulting PDF to the specified location.
pdf.SaveAs(destinationFile);
// Define the source directory containing the images.
string sourceDirectory = @"D:\web\assets";
// Define the path for the resulting PDF.
string destinationFile = "JpgToPDF.pdf";

// Get all image files in the source directory with a .jpg extension.
var imageFiles = System.IO.Directory.EnumerateFiles(sourceDirectory, "*.jpg");

// Convert the images into a single PDF.
var pdf = IronPdf.ImageToPdfConverter.ImageToPdf(imageFiles);

// Save the resulting PDF to the specified location.
pdf.SaveAs(destinationFile);
' Define the source directory containing the images.
Dim sourceDirectory As String = "D:\web\assets"
' Define the path for the resulting PDF.
Dim destinationFile As String = "JpgToPDF.pdf"

' Get all image files in the source directory with a .jpg extension.
Dim imageFiles = System.IO.Directory.EnumerateFiles(sourceDirectory, "*.jpg")

' Convert the images into a single PDF.
Dim pdf = IronPdf.ImageToPdfConverter.ImageToPdf(imageFiles)

' Save the resulting PDF to the specified location.
pdf.SaveAs(destinationFile)
$vbLabelText   $csharpLabel

To explore more about converting images to PDFs using IronPDF for enhancing your applications, or to discover the entire suite of developer tools offered by Iron Software, including IronBarcode, IronOCR, and more, visit the Iron Software website.