If you need a high-speed and high-fidelity conversion of images to PDF format, this article is going to help you a lot. Because in this article, you will learn how to easily convert an image to PDF in C#. We will explicitly cover how to convert JPG to PDF, PNG to PDF, TIFF to PDF, BMP to PDF, and EMF to PDF.

C# Image to PDF Converter API - Installation

We will be performing these image formats to PDF conversion using Aspose.PDF for .NET API. You can either download it from Releases section, or via the NuGet Gallery with the following command:

Install-Package Aspose.Pdf -Version 20.9.0

So the API has been installed successfully by now. Let us move on to explore different use cases:

Convert JPG to PDF in C#

You can easily convert a JPG image to PDF by following steps:

  1. Initialize object of Document class
  2. Add a new Page to PDF document
  3. Load JPG image and add to the paragraph
  4. Save output PDF

The code snippet below shows how to convert JPG Image to PDF using C#:

Below is the screenshot of JPG conversion to PDF:

Image to PDF

However, in this screenshot, you can notice that the image is converted to a PDF page, but, default page dimensions and margins are applied in the output PDF document. Aspose.PDF for .NET API allows you to control page dimensions and margins that help you create the same size PDF as the image dimensions. Let us proceed to explore this feature:

C# Image to PDF - Same Page Height and Width

Continuing this example from the above use case, you can notice a bigger page size in the above screenshot. Let us learn how to convert an image to a PDF with the same height and width as the page. We will be getting the image dimensions and accordingly set the page dimensions of PDF document with the below steps:

  1. Load input image file
  2. Get the height and width of the image
  3. Set height, width, and margins of a page
  4. Save the output PDF file

Following code snippet shows how to convert an Image to PDF with the same page height and width using C#:

So you can notice the difference in page dimensions that have been created with the updated code snippet:

Finally, you can notice the page size is exactly similar in accordance with input image dimensions, and no more default page margins are being set now.

C# PNG to PDF Conversion

PNG image format is popular because of its features as compared to JPG images. For example, PNG images support transparency. Firstly, let us convert PNG to PDF with the below steps:

  1. Load input PNG image
  2. Read height and width values
  3. Create new document and add Page
  4. Set page dimensions
  5. Save output file

Moreover, the code snippet below shows how to convert PNG to PDF with C# in your .NET applications:

Convert TIFF to PDF using C#

A TIFF image is different from conventional JPEG, PNG, or other formats in a way that a TIFF image can contain several frames with different images. Aspose.PDF file format is also supported, be it a single-frame or multi-frame TIFF image. So you can convert the TIFF image to PDF in your .NET applications. Therefore, we will consider an example of converting a multi-page TIFF image to a multi-page PDF document with below steps:

  1. Instantiate an instance of Document class
  2. Load input TIFF image
  3. Get FrameDimension of the frames
  4. Add new page for each frame
  5. Finally, save images to PDF pages

Moreover, the following code snippet shows how to convert multi-page or multi-frame TIFF image to PDF with C#:

Save EMF Image as PDF in C#

EMF images, also known as Enhanced Metafile Format, are device-independent images. Furthermore, you can convert EMF to PDF image using the below steps:

  1. Firstly, initialize Document class object
  2. Load EMF image file
  3. Add the loaded EMF image to a Page
  4. Save PDF document

Moreover, the following code snippet shows how to convert an EMF to PDF with C# in your .NET code snippet:

Export BMP to PDF in C#

BMP images are Bitmap images that you can convert to PDF with Aspose.PDF for .NET API. Therefore, you can follow the following steps to convert BMP images:

  1. Initialize a new Document
  2. Load input BMP image
  3. Finally, save the output PDF file

So the following code snippet follows these steps and shows how to convert BMP to PDF using C#:

Convert Image to PDF with a Free License

You can [get a free temporary license][20] and convert images to PDF without evaluation limitations.

Conclusion

After all, we have explored images to PDF conversion from different aspects in C#. Different conversions including JPG to PDF, PNG to PDF, TIFF to PDF, EMF to PDF, and BMP to PDF have been discussed in detail. Moreover, you have learned how to improve the image to PDF rendering while setting page size and margins. Furthermore, if you still have any inquiries or questions then please reach out to us at Free Support Forum.

See Also

Convert AI to PNG, JPG, PSD and PDF file with C# .NETConvert Image to DOC in C#Convert Image to DOCX in C#
Convert JPG to DOC in C# .NETConvert JPG to DOCX in C# .NETConvert PNG to DOC in C# .NET
Convert PNG to DOCX in C# .NETConvert PPT to JPG in PythonConvert SVG to PNG in Python
Create Thumbnails for PPT Slides in PythonAdjust Image Contrast, Brightness and Gamma in JavaAdjust Image Contrast, Brightness, and Gamma in C#
Convert JPG Images to PNG in C#Convert JPG Images to PNG in JavaConvert PNG Images to JPG in C#
Convert PNG Images to JPG in JavaConvert Word to Image in PythonExtract Images from Word documents in C#
Extract Images from Word Documents in JavaExtract Images from Word Documents in PythonResize Images in C#
Resize Images in JavaRotate and Flip Images in C#Rotate and Flip Images in Java