How to Convert Images to a PDF in C#
IronPDF enables C# developers to convert single or multiple images (JPG, PNG, TIFF) into PDF documents using the ImageToPdfConverter.ImageToPdf method with customizable placement behaviors and rendering options.
Converting images to PDF combines multiple image files (such as JPG, PNG, or TIFF) into a single PDF document. This process creates digital portfolios, presentations, or reports, making it easier to share and store image collections in an organized and universally readable format.
IronPDF converts single or multiple images into PDFs with unique image placements and behaviors. These behaviors include fitting to the page, centering on the page, and cropping the page. Additionally, you can add text and HTML headers and footers using IronPDF, apply watermarks with IronPDF, set custom page sizes, and include background and foreground overlays.
Quickstart: Convert Images to PDF with IronPDFConvert images into PDF documents using IronPDF's ImageToPdfConverter class. This example demonstrates how to transform an image file into a PDF, allowing you to integrate image-to-PDF functionality into your .NET C# applications. With minimal code, you can convert images to PDF for creating digital portfolios or reports.
-
1Install IronPDF with NuGet Package Manager
-
2Copy and run this code snippet.
IronPdf.ImageToPdfConverter.ImageToPdf("path/to/image.png").SaveAs("imageToPdf.pdf");IronPdf.ImageToPdfConverter.ImageToPdf("path/to/image.png").SaveAs("imageToPdf.pdf")IronPdf.ImageToPdfConverter.ImageToPdf("path/to/image.png").SaveAs("imageToPdf.pdf") -
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
Minimal Workflow (5 steps)
- Download the IronPDF C# library for converting images to PDF
- Prepare the image or images you want to convert
- Supply the image path(s) to the
ImageToPdfstatic method - Adjust the image placement and behavior in the output PDF
- Add custom text and HTML header and footer using IronPDF
How Do I Convert a Single Image to PDF?
Use the ImageToPdf static method within the ImageToPdfConverter class to convert an image to a PDF document. This method requires only the file path to the image and converts it to a PDF document with default image placement and behavior. Supported image formats include .bmp, .jpeg, .jpg, .gif, .png, .svg, .tif, .tiff, .webp, .apng, .avif, .cur, .dib, .ico, .jfif, .jif, .jpe, .pjp, and .pjpeg.
Before starting, ensure you have installed IronPDF via NuGet or downloaded the Windows installer. The library works across Windows, macOS, and Linux platforms, making it versatile for various development environments.
What Image Formats Are Supported?

IronPDF supports a comprehensive range of image formats, including raster formats like JPEG, PNG, BMP, and GIF, as well as vector formats such as SVG graphics. The library handles both standard and modern formats like WebP and AVIF, ensuring compatibility with contemporary web applications. For specialized needs, work with icon files (.ico) and cursor files (.cur).
How Do I Write the Code?
using IronPdf;
string imagePath = "meetOurTeam.jpg";
// Convert an image to a PDF
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);
// Export the PDF
pdf.SaveAs("imageToPdf.pdf");using IronPdf;
string imagePath = "meetOurTeam.jpg";
// Convert an image to a PDF
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);
// Export the PDF
pdf.SaveAs("imageToPdf.pdf");Imports IronPdf
Private imagePath As String = "meetOurTeam.jpg"
' Convert an image to a PDF
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath)
' Export the PDF
pdf.SaveAs("imageToPdf.pdf")Imports IronPdf
Private imagePath As String = "meetOurTeam.jpg"
' Convert an image to a PDF
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath)
' Export the PDF
pdf.SaveAs("imageToPdf.pdf")For more advanced scenarios, explore asynchronous PDF generation to improve performance when processing multiple images. The library also supports custom paper sizes and custom margins to ensure your images display exactly as needed.
What Does the Output Look Like?
How Do I Convert Multiple Images to PDF?
To convert multiple images into a PDF document, provide an IEnumerable object containing file paths instead of a single file path. This generates a PDF document with default image placement and behavior.
When working with multiple images, consider the PDF compression options available to optimize file size without sacrificing quality. This is particularly important when creating large portfolios or photo albums.
How Do I Process Multiple Images at Once?
using IronPdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
// Retrieve all JPG and JPEG image paths in the 'images' folder.
IEnumerable<String> imagePaths = Directory.EnumerateFiles("images").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Convert images to a PDF
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePaths);
// Export the PDF
pdf.SaveAs("imagesToPdf.pdf");using IronPdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
// Retrieve all JPG and JPEG image paths in the 'images' folder.
IEnumerable<String> imagePaths = Directory.EnumerateFiles("images").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Convert images to a PDF
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePaths);
// Export the PDF
pdf.SaveAs("imagesToPdf.pdf");Imports IronPdf
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
' Retrieve all JPG and JPEG image paths in the 'images' folder.
Private imagePaths As IEnumerable(Of String) = Directory.EnumerateFiles("images").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))
' Convert images to a PDF
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePaths)
' Export the PDF
pdf.SaveAs("imagesToPdf.pdf")Imports IronPdf
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
' Retrieve all JPG and JPEG image paths in the 'images' folder.
Private imagePaths As IEnumerable(Of String) = Directory.EnumerateFiles("images").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))
' Convert images to a PDF
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePaths)
' Export the PDF
pdf.SaveAs("imagesToPdf.pdf")What Does the Multi-Image PDF Look Like?
How Can I Control Image Placement and Behaviors?
IronPDF offers various image placement and behavior options. You can center the image on the page or fit it to the page size while maintaining its aspect ratio. All available image placements and behaviors are:
- ``TopLeftCornerOfPage
:Image is placed at the top-left corner of the page. - ``TopRightCornerOfPage
:Image is placed at the top-right corner of the page. - ``CenteredOnPage
:Image is centered on the page. - ``FitToPageAndMaintainAspectRatio
:Image fits the page while keeping its original aspect ratio. - ``BottomLeftCornerOfPage
:Image is placed at the bottom-left corner of the page. - ``BottomRightCornerOfPage
:Image is placed at the bottom-right corner of the page. - ``FitToPage
:Image fits the page. - ``CropPage
:Page is adjusted to fit the image.
These placement options work with IronPDF's page orientation and rotation features, allowing you to create professional-looking documents regardless of your image dimensions.
How Do I Apply Image Behaviors in Code?
using IronPdf;
using IronPdf.Imaging;
string imagePath = "meetOurTeam.jpg";
// Convert an image to a PDF with image behavior of centered on page
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage);
// Export the PDF
pdf.SaveAs("imageToPdf.pdf");using IronPdf;
using IronPdf.Imaging;
string imagePath = "meetOurTeam.jpg";
// Convert an image to a PDF with image behavior of centered on page
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage);
// Export the PDF
pdf.SaveAs("imageToPdf.pdf");Imports IronPdf
Imports IronPdf.Imaging
Private imagePath As String = "meetOurTeam.jpg"
' Convert an image to a PDF with image behavior of centered on page
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage)
' Export the PDF
pdf.SaveAs("imageToPdf.pdf")Imports IronPdf
Imports IronPdf.Imaging
Private imagePath As String = "meetOurTeam.jpg"
' Convert an image to a PDF with image behavior of centered on page
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.CenteredOnPage)
' Export the PDF
pdf.SaveAs("imageToPdf.pdf")What Are the Visual Differences Between Image Behaviors?
![]()
| ![]()
|
![]()
| ![]()
|
![]()
| ![]()
|
![]()
| ![]()
|
How Do I Customize PDF Rendering Options?
The ImageToPdf static method converts images by importing them as HTML <img> tags and then converting the HTML to PDF. This allows you to pass the ChromePdfRenderOptions object as a third parameter to customize the rendering process directly.
This approach provides access to all the powerful rendering options available in IronPDF, including JavaScript execution, CSS media types, and viewport configuration. You can even incorporate web fonts and icons to enhance your document's visual appeal.
How Do I Add Headers and Custom Styling?
using IronPdf;
string imagePath = "meetOurTeam.jpg";
ChromePdfRenderOptions options = new ChromePdfRenderOptions()
{
HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>",
DrawDividerLine = true,
},
};
// Convert an image to a PDF with custom header
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, options: options);
// Export the PDF
pdf.SaveAs("imageToPdfWithHeader.pdf");using IronPdf;
string imagePath = "meetOurTeam.jpg";
ChromePdfRenderOptions options = new ChromePdfRenderOptions()
{
HtmlHeader = new HtmlHeaderFooter()
{
HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>",
DrawDividerLine = true,
},
};
// Convert an image to a PDF with custom header
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, options: options);
// Export the PDF
pdf.SaveAs("imageToPdfWithHeader.pdf");Imports IronPdf
Private imagePath As String = "meetOurTeam.jpg"
Private options As New ChromePdfRenderOptions() With {
.HtmlHeader = New HtmlHeaderFooter() With {
.HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>",
.DrawDividerLine = True
}
}
' Convert an image to a PDF with custom header
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, options:= options)
' Export the PDF
pdf.SaveAs("imageToPdfWithHeader.pdf")Imports IronPdf
Private imagePath As String = "meetOurTeam.jpg"
Private options As New ChromePdfRenderOptions() With {
.HtmlHeader = New HtmlHeaderFooter() With {
.HtmlFragment = "<h1 style='color: #2a95d5;'>Content Header</h1>",
.DrawDividerLine = True
}
}
' Convert an image to a PDF with custom header
Private pdf As PdfDocument = ImageToPdfConverter.ImageToPdf(imagePath, options:= options)
' Export the PDF
pdf.SaveAs("imageToPdfWithHeader.pdf")For more complex header and footer requirements, explore our guide on HTML headers and footers. You can also add page numbers to your image-based PDFs for better organization.
What Does the Customized Output Look Like?
How Do I Handle Performance and Large Image Collections?
When dealing with large image collections or high-resolution images, implement async and multithreading techniques to improve performance. For enterprise applications, explore IronPDF's performance optimization strategies to ensure smooth operation even with substantial workloads.
Additionally, when working with images stored in cloud services, check our guide on embedding images from Azure Blob Storage for smooth cloud integration.
How Do I Convert PDFs Back to Images?
To convert or rasterize a PDF document into images, refer to our guide on how to rasterize PDFs to images.
Ready to see what else you can do? Check out our tutorial page here: Convert PDFs
Frequently Asked Questions
How can I convert a single image to PDF in C# using IronPDF?
To convert a single image to PDF, use the ImageToPdf static method within the ImageToPdfConverter class. You need to supply the file path of the image, and the method will handle the conversion with default image placement and behavior. Supported formats include .bmp, .jpeg, .jpg, .png, and more.
What are the supported image formats for conversion using IronPDF?
IronPDF supports a wide range of image formats, including raster formats like JPEG, PNG, BMP, and GIF, as well as vector formats like SVG. It also supports standard and modern formats such as WebP and AVIF, ensuring enhanced compatibility across web applications.
Can I convert multiple images into a single PDF document with IronPDF?
Yes, you can convert multiple images into a single PDF by providing an IEnumerable object containing the file paths of the images to the ImageToPdf method. This allows you to generate a PDF document with all the images.
How do I customize image placement and behaviors in the PDF using IronPDF?
IronPDF provides various image placement options like centering on the page, fitting to the page while maintaining the aspect ratio, and placing images at specific corners. You can select these behaviors to ensure your images appear as desired in the PDF.
Can I add custom headers and footers when converting images to PDF with IronPDF?
Yes, IronPDF allows you to add text and HTML headers and footers to your PDF. You can customize these elements to include page numbers or other relevant information, enhancing the presentation and organization of your document.
How do I handle large image collections for PDF conversion in IronPDF?
For large image collections or high-resolution images, it's beneficial to implement async and multi-threading techniques to boost performance. IronPDF supports these methods to ensure efficient processing even with substantial workloads.
What are the rendering customization options available in IronPDF?
IronPDF allows you to use the ChromePdfRenderOptions object to customize the rendering process. This includes options like JavaScript execution, CSS media types, and custom headers. You can also incorporate web fonts and icons for a more polished document.
Is it possible to convert a PDF back to an image using IronPDF?
Yes, IronPDF supports converting or rasterizing PDF documents back into images. This can be useful for various applications that require different formats for distribution or presentation.
Can IronPDF work on different operating systems?
IronPDF is versatile and can operate across Windows, macOS, and Linux environments, making it an excellent choice for various development platforms.
How do I optimize PDF size when combining multiple images using IronPDF?
IronPDF offers PDF compression options to optimize the file size when merging multiple images. It's especially useful when creating large digital portfolios or photo albums, ensuring quality is maintained without large file sizes.
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.







