Skip to footer content
USING IRONPDF

Convert JPEG to PDF .NET: The Complete C# Developer Guide

Convert JPG images to PDF in C# using IronPDF's ImageToPdfConverter class with just 3 lines of code. This approach handles single images or batch conversion of multiple JPGs into one PDF document while preserving image quality.

Diagram showing JPEG to PDF conversion process with a landscape photo being converted from JPG format to PDF format, indicated by a blue arrow between the two file icons.

For developers building document management systems or archival tools, converting JPG images to the universal PDF format is essential. You need a reliable PDF converter to efficiently handle multiple JPG files and combine them into a single PDF file.

This guide is your complete C# Developer Guide for converting JPEG to PDF .NET programmatically. We use IronPDF as your dedicated JPG to PDF converter, handling the entire conversion process in just a few lines of code. Whether you're working with ASP.NET applications or building Windows desktop software, IronPDF provides consistent results across platforms.

Whether converting a single image or batch processing multiple JPG images, our approach ensures high image quality and supports various image formats. This PDF tool enables simple PDF conversion across any operating system and device. Unlike many online PDF converters, IronPDF runs entirely within your application, ensuring data privacy and eliminating upload/download delays.

NuGet Install with NuGet

PM >  Install-Package IronPdf

Check out IronPDF on NuGet for quick installation. With over 10 million downloads, it’s transforming PDF development with C#. You can also download the DLL or Windows installer.

How Can I Convert JPG Images to a PDF File?

The simplest approach to convert JPG to PDF uses IronPDF's ImageToPdfConverter class. This JPG to PDF converter works with the image file path and produces a high-quality PDF document automatically. For developers familiar with HTML to PDF conversion, the image conversion process is similarly straightforward.

using IronPdf;
// Convert a single JPG image to PDF
string imagePath = "photo.jpg";
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);
// Save the converted PDF file
pdf.SaveAs("converted-photo.pdf");
using IronPdf;
// Convert a single JPG image to PDF
string imagePath = "photo.jpg";
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath);
// Save the converted PDF file
pdf.SaveAs("converted-photo.pdf");
$vbLabelText   $csharpLabel

The conversion happens entirely in memory, making it ideal for web applications where you might need to serve the PDF directly without saving to disk. You can also integrate this with Azure Blob Storage for cloud-based image processing workflows.

How Does the Output PDF Compare to the Original JPG?

Screenshot showing IronPDF website on the left and the resulting PDF conversion on the right, demonstrating the HTML to PDF conversion feature with C# code examples visible.

The ImageToPdf method accepts the file path to your JPG file and returns a PdfDocument object. This converted PDF maintains the original file's image quality while packaging it in a universally accessible PDF format. The conversion process completes in a few seconds, and the tool automatically handles page sizing. For precise control over dimensions, you can specify custom margins and page orientation.

IronPDF supports numerous image formats beyond JPEG, including PNG, BMP, GIF, TIFF, and SVG. This flexibility means the same image to PDF converter code works regardless of whether you're processing JPG pictures, PNG graphics, or other image files. You can convert images from virtually any source, including embedded images in HTML or Base64-encoded data.

How Do I Convert Multiple JPG Files into One PDF Document?

Batch processing multiple JPG images into a single PDF document is equally straightforward. Simply pass all your image paths to the JPG to PDF converter, and it combines them into one PDF file with each image on its own page. This approach works well for creating photo portfolios or document archives.

using IronPdf;
using System.IO;
using System.Linq;
// Gather all JPG files from a folder
var imagePaths = Directory.EnumerateFiles("photos")
    .Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Convert multiple JPG images to a single PDF file
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePaths);
// Download or save the combined PDF
pdf.SaveAs("photo-collection.pdf");
// Optional: Add page numbers to the collection
pdf.AddTextHeaders("{page} of {total-pages}", 
    IronPdf.Editing.TextHeaderFooter.Alignment.Center);
pdf.SaveAs("photo-collection-numbered.pdf");
using IronPdf;
using System.IO;
using System.Linq;
// Gather all JPG files from a folder
var imagePaths = Directory.EnumerateFiles("photos")
    .Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Convert multiple JPG images to a single PDF file
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePaths);
// Download or save the combined PDF
pdf.SaveAs("photo-collection.pdf");
// Optional: Add page numbers to the collection
pdf.AddTextHeaders("{page} of {total-pages}", 
    IronPdf.Editing.TextHeaderFooter.Alignment.Center);
pdf.SaveAs("photo-collection-numbered.pdf");
$vbLabelText   $csharpLabel

For even more control, you can process images individually and then merge the PDFs:

// Process images with custom settings
var pdfDocuments = new List<PdfDocument>();
foreach (var imagePath in imagePaths)
{
    var pdf = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.FitToPageAndMaintainAspectRatio);
    pdfDocuments.Add(pdf);
}
// Merge all PDFs into one
var combinedPdf = PdfDocument.Merge(pdfDocuments);
combinedPdf.SaveAs("custom-photo-collection.pdf");
// Process images with custom settings
var pdfDocuments = new List<PdfDocument>();
foreach (var imagePath in imagePaths)
{
    var pdf = ImageToPdfConverter.ImageToPdf(imagePath, ImageBehavior.FitToPageAndMaintainAspectRatio);
    pdfDocuments.Add(pdf);
}
// Merge all PDFs into one
var combinedPdf = PdfDocument.Merge(pdfDocuments);
combinedPdf.SaveAs("custom-photo-collection.pdf");
$vbLabelText   $csharpLabel

What Files Does the Converter Process?

Seven document pages displayed in a row, numbered 1-7, showing various text layouts and images that appear to be sample files for PDF conversion.

How Are Multiple Images Arranged in the PDF?

PDF document viewer displaying a multi-page Wikipedia article with embedded images, showing pages 1-9 of the converted output at 25% zoom

This code enumerates JPG files from a directory, filters for JPEG image formats, and passes the collection to the PDF converter. The result is a single PDF document containing all your JPG images in their original order. You can arrange the images in your desired order before conversion by sorting the file paths accordingly. For more advanced organization, consider adding bookmarks or a table of contents.

This approach is perfect for creating photo albums, document archives, or combining scanned pages. The converted PDF files preserve each image's quality while making the collection easy to share and view on any device, whether Windows, Mac, or mobile device. Converting multiple images into one PDF streamlines document workflows significantly. You can even password-protect the resulting PDF for secure sharing.

What Image Formats Does This PDF Converter Support?

IronPDF's image to PDF converter supports a comprehensive range of image formats, making it a versatile PDF tool for any conversion scenario. Unlike some converters that only handle basic formats, IronPDF processes everything from common web images to professional TIFF files:

FormatExtensionsBest ForSpecial Features
JPEG.jpg, .jpeg, .jfifPhotos, scanned documentsExcellent compression
PNG.pngGraphics with transparencyLossless quality
BMP.bmpUncompressed imagesRaw image data
GIF.gifSimple graphicsAnimation support
TIFF.tiff, .tifHigh-quality scansMulti-page support
SVG.svgVector graphicsScalable rendering
WebP.webpModern web imagesBetter compression

Whether you need to convert images from JPG pictures, PNG files, or even process image files extracted from DOCX documents, these PDF tools handle the conversion seamlessly. Unlike an online tool or online service, this approach eliminates file upload concerns. Your files stay secure in memory and everything runs locally within your .NET application. Other PDF tools may require additional software installation, but IronPDF works immediately after NuGet installation.

For specialized formats, IronPDF also supports rendering WebGL content and JavaScript-generated graphics, making it suitable for converting complex visual content beyond static images.

How Can I Control Image Placement in the Converted PDF?

IronPDF offers several ImageBehavior options that control how images appear on PDF pages. These include FitToPageAndMaintainAspectRatio for scaling images while preserving proportions, CenteredOnPage for center-aligned placement, TopLeftCornerOfPage for precise positioning, and CropPage to match page size exactly to image dimensions. You can combine these with custom paper sizes for perfect layouts.

// Custom image placement example
var renderingOptions = new ImageToPdfRenderOptions
{
    ImageBehavior = ImageBehavior.FitToPageAndMaintainAspectRatio,
    PaperSize = PdfPaperSize.A4,
    MarginTop = 25,
    MarginBottom = 25,
    MarginLeft = 25,
    MarginRight = 25
};
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, renderingOptions);
// Add a watermark to the converted image
pdf.ApplyWatermark("<h2 style='color:red'>CONFIDENTIAL</h2>", 30, 
    VerticalAlignment.Middle, HorizontalAlignment.Center);
// Custom image placement example
var renderingOptions = new ImageToPdfRenderOptions
{
    ImageBehavior = ImageBehavior.FitToPageAndMaintainAspectRatio,
    PaperSize = PdfPaperSize.A4,
    MarginTop = 25,
    MarginBottom = 25,
    MarginLeft = 25,
    MarginRight = 25
};
PdfDocument pdf = ImageToPdfConverter.ImageToPdf(imagePath, renderingOptions);
// Add a watermark to the converted image
pdf.ApplyWatermark("<h2 style='color:red'>CONFIDENTIAL</h2>", 30, 
    VerticalAlignment.Middle, HorizontalAlignment.Center);
$vbLabelText   $csharpLabel

You can also customize page margins, rotate PDF pages to adjust orientation, and apply headers or footers to the output. For developers needing even more control over the PDF format, the ChromePdfRenderOptions parameter allows fine-tuning of the conversion process. The JPG to PDF converter works effectively whether your source files are portrait or landscape orientation.

Additional customization options include:

What Are Common Use Cases for JPEG to PDF Conversion?

Programmatic JPG to PDF conversion serves many practical purposes across different industries and applications:

  • Document Archival: Convert scanned pages and photos into organized PDF documents for long-term storage
  • Report Generation: Embed charts and screenshots into professional PDF reports
  • Photo Portfolios: Combine many images into presentable PDF collections using the image to PDF workflow
  • Digital Workflows: Automate the conversion of uploaded JPG images into PDF documents within web applications

The converted PDF files work across any operating system and mobile device, ensuring recipients can view documents without requiring additional software. Whether you convert JPG to PDF for archival or distribution, the output maintains high-quality results. For enhanced security, you can sanitize PDFs to remove metadata or apply redaction to sensitive areas.

What's Next for My JPG to PDF Implementation?

IronPDF's JPG to PDF converter simplifies image to PDF conversion for .NET developers. With support for multiple image formats, batch processing capabilities, and flexible placement options, it handles everything from converting a single image file to combining multiple JPG images into comprehensive PDF documents, all with just a few lines of code. The library integrates seamlessly with Blazor applications, MAUI projects, and traditional desktop software.

For production deployments, consider implementing async processing for better performance and custom logging for monitoring. The library supports deployment to Docker and various cloud platforms with comprehensive troubleshooting guides available.

The free trial lets you test all features, and purchasing a license unlocks full production capabilities. Start your free trial today to convert JPG to PDF efficiently in your .NET applications. Check our licensing options for startups and enterprises, with flexible terms that scale with your business.

Frequently Asked Questions

How can I convert a JPEG to PDF using .NET?

You can convert a JPEG to PDF in .NET using IronPDF's ImageToPdfConverter class. This class allows you to transform single or multiple JPG images into PDF documents easily.

What is the ImageToPdfConverter class in IronPDF?

The ImageToPdfConverter class in IronPDF is a tool designed to convert image files, such as JPEGs, into PDF documents within a .NET application.

Can I convert multiple JPEG images to a single PDF document?

Yes, IronPDF allows you to convert multiple JPEG images into a single PDF document using the ImageToPdfConverter class.

Is it possible to automate JPEG to PDF conversion in C#?

Yes, you can automate JPEG to PDF conversion in C# by leveraging IronPDF's ImageToPdfConverter class within your .NET applications.

What are the prerequisites for using IronPDF to convert JPEG to PDF?

To use IronPDF for JPEG to PDF conversion, you need to have a .NET development environment set up, and you should include the IronPDF library in your project.

How do I handle large batches of JPEG files for PDF conversion?

IronPDF can efficiently handle large batches of JPEG files for PDF conversion by iterating over the image collection using the ImageToPdfConverter class.

Does IronPDF support other image formats for conversion to PDF?

Yes, besides JPEG, IronPDF supports various image formats for conversion to PDF, including PNG and BMP, using the same ImageToPdfConverter class.

Can IronPDF preserve image quality during conversion?

IronPDF is designed to maintain high-quality output during the conversion of JPEG images to PDF, ensuring that the images in the resulting PDF document are clear and sharp.

Is IronPDF suitable for creating PDFs from images in commercial applications?

Yes, IronPDF is well-suited for use in commercial applications, providing robust tools for converting images to PDFs efficiently and effectively.

How can I integrate IronPDF into my existing .NET project?

You can integrate IronPDF into your existing .NET project by installing the IronPDF library via NuGet Package Manager and utilizing its classes, like ImageToPdfConverter, in your code.

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