Merge JPG to PDF in C# | Merge JPG as PDF

Merging multiple JPG images into a single PDF is a common requirement for various applications, including document management systems, report generation, and digital archiving. In this blog post, we will walk you through the process of merging JPG images into a PDF using C#.

This article covers the following topics:

  1. C# Library to Merge JPG to PDF
  2. Merge Multiple JPG Images to a PDF in C#
  3. Combine Multiple JPGs into a PDF
  4. Merge JPG to PDF Online
  5. Free Resources

C# Library to Merge JPG to PDF

We will use Aspose.PDF for .NET for merging JPG images into a PDF using C#. It is a powerful library for PDF manipulation that enables developers to create, manipulate, and manage PDF documents programmatically in .NET applications.

Please download the DLL of the API or install it using NuGet with the following command:

PM> Install-Package Aspose.PDF

Merge Multiple JPG Images to a PDF in C#

We can easily merge multiple JPG images into a PDF document by following the steps below:

  1. Read all JPG files from a directory.
  2. Merge JPG images into a Stream using the PdfConverter.MergeImages() method.
  3. Create an instance of the Document class.
  4. Add a new empty page to the Document Pages collection.
  5. Create an instance of the Image class.
  6. Set the Image.ImageStream property.
  7. Add an image to the page.
  8. Finally, save the document using the Save() method.

The following code sample shows how to merge JPG images into a PDF document in C#.

Merge Multiple JPG Images to a PDF in C#

Merge Multiple JPG Images to a PDF in C#

Combine Multiple JPGs to PDF

Similarly, we can combine multiple JPG images into a PDF document by following the steps below:

  1. Create an instance of Document class.
  2. Get the list of all JPG files in a directory using the Directory.GetFiles(string) method.
  3. For each image file in the list, do the following:
    • Add a new Page to the PDF document.
    • Load the image file into a FileStream object.
    • Add a new Image to the page using Page.Paragraphs.Add(Image) method.
    • Set the image’s stream using the Image.ImageStream property.
  4. Finally, save the PDF document using the Document.Save(String) method.

The following code sample shows how to combine multiple JPG images into a PDF document in C#.

Get a Free License!

Visit our Temporary License page to get a complimentary, unrestricted license and unlock the full potential of Aspose.PDF for .NET with no limitations!

Merge JPG to PDF Online

In addition, you may also merge your JPG images into a PDF document online for free using this JPG to PDF merger tool.

Merge JPG as PDF – Free Resources

Besides merging JPG images to a PDF document, learn how to create, manipulate, and convert PDF documents, along with exploring various other features of the library, using the resources provided below:

Conclusion

In this article, we have learned how to merge JPGs to a PDF in C#. We have also seen how to programmatically combine JPG images in a PDF document. By following the steps outlined in this blog post, you can easily create a PDF document from multiple images. If you have any questions, feel free to let us know via our free support forum.

See Also