.NET PDF Examples
Convert Images to PDFs in C# with the .NET PDF Library
The Syncfusion® .NET PDF Library offers powerful capabilities for creating, reading, and editing PDF documents. One of its robust features is the ability to convert various image formats, such as PNG, JPEG, BMP, and TIFF, into PDF documents, enabling easy archiving, sharing, and document standardization.
Watch this video to see how to convert images into high‑quality PDF files using the Syncfusion .NET PDF Library.
Convert images to PDF documents in C#
Learn how to programmatically convert images (PNG, JPEG, BMP, TIFF) to PDF format in C# using the Syncfusion .NET PDF Library. This guide explains how to perform image-to-PDF conversion and customize the layout.
Step 1: Create a new C# Console Application project
Begin by creating a new C# Console Application project in Visual Studio or your preferred IDE to implement image-to-PDF conversion functionality.
Step 2: Install Syncfusion PDF Imaging NuGet package
Install the Syncfusion.Pdf.Imaging.Net.Core NuGet package in your C# project from NuGet.org. This package provides APIs for converting various image formats to PDF.
Step 3: Add required namespace for image to PDF conversion
Import the following namespace in your Program.cs file to access image converter classes and PDF document methods:
using Syncfusion.Pdf;Step 4: Create and configure the image to PDF converter
Create an instance of the ImageToPdfConverter class. Configure the page size and image position settings for the output PDF document.
// Create an instance of the ImageToPdfConverter class
ImageToPdfConverter imageToPdfConverter = new ImageToPdfConverter();
// Set the page size for the document
imageToPdfConverter.PageSize = PdfPageSize.A4;
// Set the position of the image in the document
imageToPdfConverter.ImagePosition = PdfImagePosition.TopLeftCornerOfPage;Step 5: Convert the image to PDF
Create a FileStream to read the image file (JPEG, PNG, BMP, or TIFF). Use the Convert method to transform the image into a PDF document with the configured settings. Save the converted PDF document using the Save method.
// Create a file stream to read the image file
using (FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read))
{
// Convert the image to a PDF document using the ImageToPdfConverter
using (PdfDocument pdfDocument = imageToPdfConverter.Convert(imageStream))
{
//Save the PDF document
pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));
}
}GitHub project
NuGet installation
Get started quickly by downloading the installer and checking license information on the Downloads page.
Table of contents
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Learning
Technical Support
