Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
This article will guide you on how to convert PNG to PDF using IronPDF image conversion API in C#.
ImageToPdf
methodIn this tutorial, the following topics will be covered:
Requirements when using IronPDF:
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, CSS, and images. 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:
Here, this tutorial focused on the conversion of PNG files to PDF documents. IronPDF supports almost every image format for conversion. Supported image formats are JPG images, PNG, GIF, TIFF, SVG, and BMP.
This tutorial will use the latest version of Visual Studio and C# programming language to build the project. As the example code is derived from C# 10.0, you should have some knowledge concerning top-level statements.
Let's begin by creating a C# project.
Console Program after Creating Project
Open from Solution Explorer
Once the NuGet Package Manager Solution is open, browse for the IronPDF library to convert a PNG image to a PDF file. Then click on install.
Browse IronPDF
Using the NuGet Package Manager Console will allow you to install the library effortlessly. Administrative privilege is not required to install the library. A NuGet command will be used to install the IronPDF library in your project. Just utilize the following command to proceed.
Install-Package IronPdf
You can directly download the IronPDF .DLL file from the website. It can be instantly downloaded from the IronPDF DLL download.
To reference the library in your project follow these directions:
All done! IronPDF is downloaded, installed, and ready to use to convert PNG to PDF format.
Now add the IronPDF namespace to your program. You have to add a given line of code at the top of the file.
using IronPdf;
using IronPdf;
Imports IronPdf
This will allow you to access all of the functions provided by IronPDF. This line of code must be added to every file where you wish to use the IronPDF features.
Converting PNG files to PDF documents is very easy with IronPDF. Only one line of code can achieve this task using the IronPDFs ImageToPdf
method. Inside the directory of the project, place the PNG images to be converted inside a folder named assets. The folder must be placed in the location: bin\Debug\net6.0. Then, using System.IO.Directory, enumerate the assets folder with all the PNG files and pass it to the ImageToPdf
method for the conversion operation stream. The following code example helps you convert a PNG image to a PDF document and save a Stream object to the disk.
using IronPdf;
Console.WriteLine("C# Convert PNG to PDF using IronPDF");
// One or more images as IEnumerable. This example selects all PNG images in a specific 'assets' folder.
var image = System.IO.Directory.EnumerateFiles("assets").Where(f => f.EndsWith(".png") || f.EndsWith(".PNG"));
// Converts the images to a PDF and saves it.
ImageToPdfConverter.ImageToPdf(image).SaveAs("composite.pdf");
// Print success message
Console.WriteLine("PNG successfully converted to PDF");
using IronPdf;
Console.WriteLine("C# Convert PNG to PDF using IronPDF");
// One or more images as IEnumerable. This example selects all PNG images in a specific 'assets' folder.
var image = System.IO.Directory.EnumerateFiles("assets").Where(f => f.EndsWith(".png") || f.EndsWith(".PNG"));
// Converts the images to a PDF and saves it.
ImageToPdfConverter.ImageToPdf(image).SaveAs("composite.pdf");
// Print success message
Console.WriteLine("PNG successfully converted to PDF");
Imports IronPdf
Console.WriteLine("C# Convert PNG to PDF using IronPDF")
' One or more images as IEnumerable. This example selects all PNG images in a specific 'assets' folder.
Dim image = System.IO.Directory.EnumerateFiles("assets").Where(Function(f) f.EndsWith(".png") OrElse f.EndsWith(".PNG"))
' Converts the images to a PDF and saves it.
ImageToPdfConverter.ImageToPdf(image).SaveAs("composite.pdf")
' Print success message
Console.WriteLine("PNG successfully converted to PDF")
In the above code snippet, the asset folder contains only one PNG file. The output file looks like this:
Single JPG file to PDF file
The same code example can be used to convert multiple PNG images. The output file formats contain three PNG-to-PDF documents.
Multiple PNG Images to PDF Document
This tutorial shows how to convert a PNG image to a PDF document using the IronPDF C# library. The manipulation and configuration of PDF files becomes remarkably effortless with the IronPDF library function. All that is needed is just a few lines of code to construct a PDF document from PNG files. Whether it's to convert JPG images, PNG images, or numerous other formats, IronPDF is ideal for developers and companies.
Utilize the free version to test it out! Additionally, 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! Visit this licensing page for more information about licensing.
9 .NET API products for your office documents