Images To PDF
Construct a PDF from one or more 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
, we can convert it quickly into a PDF document by calling the IronPdf.ImageToPdfConverter.ImageToPdf
method with its file path:
IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png").SaveAs("example.pdf");
IronPdf.ImageToPdfConverter.ImageToPdf(@"C:\images\example.png").SaveAs("example.pdf");
IronPdf.ImageToPdfConverter.ImageToPdf("C:\images\example.png").SaveAs("example.pdf")
Combine Multiple Images Into a PDF File
We can also convert images to PDFs in batch into a single PDF document using System.IO.Directory.EnumerateFiles
along with ImageToPdfConverter.ImageToPdf
:
string sourceDirectory = "D:\web\assets";
string destinationFile = "JpgToPDF.pdf";
var imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg");
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile);
string sourceDirectory = "D:\web\assets";
string destinationFile = "JpgToPDF.pdf";
var imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg");
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile);
Dim sourceDirectory As String = "D:\web" & ChrW(7) & "ssets"
Dim destinationFile As String = "JpgToPDF.pdf"
Dim imageFiles = Directory.EnumerateFiles(sourceDirectory, "*.jpg")
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs(destinationFile)
Explore more about converting images to PDFs using IronPDF to enhance your applications, or visit the Iron Software website to discover the entire suite of developer tools offered by Iron Software, including IronBarcode, IronOCR, and more.