Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
This article will walk you through converting JPG formats to PDF format programmatically in C#, using the IronPDF library super fast.
ImageToPdfConverter
class to convert JPG to PDFIn this tutorial, the following topics will be covered:
Requirements when using IronPDF:
Before starting, you should have some knowledge regarding top-level statements, as the basic code is extracted from C# 10.0.
Let's begin by creating a C# project.
Visual Studio supplies the NuGet Package Manager to download NuGet packages in your projects. You can access it through the Tools Menu or by right-clicking your project in Solution Explorer.
Open from Solution Explorer
Once the NuGet Package Manager Solution panel is open, search for the IronPDF library. Select install.
Browse IronPDF
The NuGet Package Manager Console can also be used to easily install the library. Administrative privileges are not required for installation. Use a NuGet command to install the IronPDF library in your project. Copy the code snippet in the NuGet Package Manager Console and press enter. The IronPDF library will be installed and ready to use in your project.
Install-Package IronPdf
You can also download the IronPDF .DLL file directly from the official website.
After unzipping the file, reference the library in your project by following these steps:
All done! IronPDF is downloaded, installed, and ready to use to convert JPG to PDF format.
To use IronPDF features, you need to add the IronPDF namespace to your program. Add the provided line of code to the top of the file.
using IronPdf;
using IronPdf;
Imports IronPdf
This will allow you to access the functions of the IronPDF library. You are required to add this line of code to every file to use the IronPDF features.
The conversion of JPG images to PDF files can be achieved in a single line with IronPDF. The code is neat, clean, and understandable. This task can be achieved using IronPDF's ImageToPdfConverter
method. Follow the steps below to convert any JPG image to a PDF document.
First, place all JPG file formats to be converted inside a folder named "assets" located in the directory of the project. The folder must be placed in the location: bin\Debug\net6.0.
Then using System.IO.Directory
, enumerate the assets folder with all the JPG files and pass it to the ImageToPdf
method for PDF conversion. The following code snippet helps convert JPG to PDF images and saves them to a new document.
using IronPdf;
Console.WriteLine("C# Convert Images (JPG to PDF) using IronPDF");
// Selects all JPG/JPEG images in the folder 'assets'.
var images = System.IO.Directory.EnumerateFiles("assets")
.Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Converting images to PDF and saving the result as "composite.pdf".
ImageToPdfConverter.ImageToPdf(images).SaveAs("composite.pdf");
// Print success message
Console.WriteLine("JPG successfully converted to PDF using C#");
using IronPdf;
Console.WriteLine("C# Convert Images (JPG to PDF) using IronPDF");
// Selects all JPG/JPEG images in the folder 'assets'.
var images = System.IO.Directory.EnumerateFiles("assets")
.Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Converting images to PDF and saving the result as "composite.pdf".
ImageToPdfConverter.ImageToPdf(images).SaveAs("composite.pdf");
// Print success message
Console.WriteLine("JPG successfully converted to PDF using C#");
Imports IronPdf
Console.WriteLine("C# Convert Images (JPG to PDF) using IronPDF")
' Selects all JPG/JPEG images in the folder 'assets'.
Dim images = System.IO.Directory.EnumerateFiles("assets").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))
' Converting images to PDF and saving the result as "composite.pdf".
ImageToPdfConverter.ImageToPdf(images).SaveAs("composite.pdf")
' Print success message
Console.WriteLine("JPG successfully converted to PDF using C#")
In the above code snippet, the assets
folder can contain multiple JPG images. Each image will be added to the PDF document as a separate page.
The same code example can be used to convert multiple JPG files. The output contains three JPG images in a PDF document.
Multiple JPG Images to PDF Document
This tutorial shows how to convert JPG images to PDF documents using the IronPDF C# library. The manipulation and formatting of PDF files become significantly effortless using the IronPDF library function. All that is required is just a few lines of code to create a PDF document from JPG files. This assists in sending all images in a single PDF document, conserving time in uploading and downloading. You can also convert TIFF and other image formats using IronPDF just like the JPG tutorial.
The IronPDF .NET PDF Library solution is a dream for developers, particularly software engineers who use C#. Using this excellent Iron Software tool, you can easily create a core PDF library for .NET. IronPDF will ensure any PDF conversion from different formats is an effortless and time-saving process.
It also enables you to construct a PDF file using HTML5, JavaScript, and CSS efficiently. You can seamlessly edit, stamp, and add headers and footers to a PDF. Furthermore, it makes it very easy to read PDF text, extract images or convert images to PDF programmatically.
Some of the important features include:
This tutorial focused on the conversion of a JPG image to a PDF document. IronPDF supports almost every image format for conversion. Supported formats are JPG, PNG, TIFF, GIF, SVG, and BMP. You can try the free version of IronPDF to test it out and with a free trial key, you can test the functionality of IronPDF. Furthermore, the current special offer allows you to get five products from IronPDF for the price of just two! Information regarding licensing can be found on this IronPDF Licensing Information page.
IronPDF is a .NET PDF Library that allows developers to create, edit, and convert PDF files using C# with ease. It supports various features including converting images to PDF, merging PDF documents, and more.
To convert JPG to PDF using C#, you can use the IronPDF library. First, install the IronPDF library via NuGet, then use the ImageToPdfConverter class to perform the conversion with minimal lines of code.
ImageToPdfConverter is a method in the IronPDF library that allows you to convert image files, such as JPGs, into PDF documents programmatically in C#.
Yes, you can convert multiple JPG files into a single PDF document using IronPDF. Place the images in a directory, use System.IO.Directory to enumerate them, and pass them to the ImageToPdf method.
To use IronPDF, you should have a basic knowledge of C# and Windows Applications. Additionally, you need to have a development environment like Visual Studio and .NET Core, preferably version 6.0.
IronPDF can be installed in a C# project using the NuGet Package Manager, the NuGet Package Manager Console, or by downloading the DLL file from the official IronPDF website and adding it as a reference in your project.
IronPDF supports conversion of various image formats including JPG, PNG, TIFF, GIF, SVG, and BMP to PDF documents.
Yes, IronPDF offers a free trial version which allows you to test its functionalities. You can obtain a free trial key from their website.
Yes, IronPDF allows you to edit PDFs, including adding headers and footers, stamping, merging documents, and more.
Yes, IronPDF can convert HTML, including HTML5, JavaScript, and CSS, into PDF documents, making it a versatile tool for developers.