If you need a fast, high‑fidelity conversion of images to PDF, this article shows you how to convert images to PDF in C#. We cover JPG, PNG, TIFF, BMP, and EMF conversions.

C# Image to PDF Converter API - Installation

We will perform the image‑to‑PDF conversion using the Aspose.PDF for .NET API. Download it from the Releases page or install it via NuGet:

Install-Package Aspose.Pdf -Version 20.9.0

The API is now installed. Let’s explore the different use cases.

Convert JPG to PDF in C#

Follow these steps to convert a JPG image to PDF:

  1. Initialize a Document object.
  2. Add a new page to the PDF.
  3. Load the JPG image and add it to a paragraph.
  4. Save the output PDF.

The snippet below demonstrates JPG‑to‑PDF conversion in C#:

{{< gist aspose-cloud 7b6fd21096e2fbbda3548cdd8c565b96 “Image-to-PDF.cs” >}}

Screenshot of the JPG conversion:

{{< figure align=center src=“images/Image-To-PDF.png” alt=“Image to PDF”>}}

By default, the PDF uses standard page dimensions and margins. The Aspose.PDF for .NET API lets you set custom page size and margins to match the image dimensions.

C# Image to PDF - Same Page Height and Width

Continuing from the previous example, you can create a PDF page that matches the exact height and width of the source image. Steps:

  1. Load the input image file.
  2. Retrieve the image’s height and width.
  3. Set the PDF page’s height, width, and margins accordingly.
  4. Save the PDF.

The code below shows how to achieve this:

{{< gist aspose-cloud 7b6fd21096e2fbbda3548cdd8c565b96 “JPG-to-PDF.cs” >}}

Resulting PDF with matching dimensions:

{{< figure align=center src=“images/JPG-to-PDF-1024x648.png” alt="">}}

The page size now mirrors the original image, and default margins are removed.

C# PNG to PDF Conversion

PNG images support transparency, making them useful for many scenarios. Convert PNG to PDF with these steps:

  1. Load the PNG image.
  2. Read its height and width.
  3. Create a new document and add a page.
  4. Set the page dimensions.
  5. Save the PDF.

Code example:

{{< gist aspose-cloud 7b6fd21096e2fbbda3548cdd8c565b96 “PNG-to-PDF.cs” >}}

Convert TIFF to PDF using C#

A TIFF file can contain multiple frames. Aspose.PDF handles both single‑frame and multi‑frame TIFF images. To convert a multi‑page TIFF to a multi‑page PDF:

  1. Create a Document instance.
  2. Load the TIFF image.
  3. Get the FrameDimension of each frame.
  4. Add a new PDF page for each frame.
  5. Save the document.

Code example:

{{< gist aspose-cloud 7b6fd21096e2fbbda3548cdd8c565b96 “TIFF-to-PDF.cs” >}}

Save EMF Image as PDF in C#

EMF (Enhanced Metafile Format) images are device‑independent. Convert EMF to PDF with these steps:

  1. Initialize a Document object.
  2. Load the EMF image.
  3. Add the image to a PDF page.
  4. Save the PDF.

Code example:

{{< gist aspose-cloud 7b6fd21096e2fbbda3548cdd8c565b96 “EMF-to-PDF.cs” >}}

Export BMP to PDF in C#

BMP bitmap images can also be converted to PDF. Follow these steps:

  1. Create a new Document.
  2. Load the BMP image.
  3. Save the PDF.

Code example:

{{< gist aspose-cloud 7b6fd21096e2fbbda3548cdd8c565b96 “BMPtoPDF.cs” >}}

Convert Image to PDF with a Free License

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

Conclusion

We have covered image‑to‑PDF conversion in C# for JPG, PNG, TIFF, EMF, and BMP formats. You now know how to control page size and margins for optimal rendering. For further assistance, visit our 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