How to Convert Image to PDF in C#

This step-by-step tutorial shows you how to convert Image to PDF in C#. This example code helps you to quickly transform JPG image to PDF document with few lines of code. Further, you can easily convert Image to PDF using C# for other image formats such as PNG, TIFF, BMP, and many more.

Steps to Convert Image to PDF in C#

  1. Setup GroupDocs.Conversion for .NET from the NuGet to convert image to PDF using C#
  2. Add GroupDocs.Conversion namespace
  3. Create an instance of the Converter class and load the Image for conversion to PDF
  4. Create an instance of the PdfConvertOptions class
  5. Invoke the Convert method of the Converter class, provide the name for the PDF file and options for it

These steps cover everything you need to know about setting up the project and using the C# Image to PDF conversion functionality. To convert a JPG file to PDF, you must first install the needed library via the NuGet package manager. Finally, you may define settings for the converted PDF file and save it to the disk.

Code to Convert Image to PDF in C#

using System;
using GroupDocs.Conversion.Options.Convert;
namespace ConvertImageToPdfInCSharp
{
class Program
{
public static void Main(string[] args) // Main function to convert Image to PDF using C#
{
// Remove the watermark in output PDF document by adding license
string licensePath = "GroupDocs.Conversion.lic";
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License();
lic.SetLicense(licensePath);
// Load the source Image file for conversion to PDF
var converter = new GroupDocs.Conversion.Converter("sample.jpg");
// Set the convert options for PDF format
var options = new PdfConvertOptions();
// Save converted PDF file
converter.Convert("converted.pdf", options);
Console.WriteLine("Done");
}
}
}

We have discussed in this tutorial how to do the conversion of Image to PDF in C#. Moreover, you can convert images to other document formats including Microsoft Word, Excel and Powerpoint formats. In this example, we have used JPG for the conversion to PDF and you can use other image formats such as PNG, BMP, GIF etc. for conversion.

If you want to convert PDF to Word in C# then refer to our other how to guide.

 English