How to merge images to PDF using C#

PDF Merger .NET API

GroupDocs.Merger allows developers to combine multiple image documents in the preferred order and save them as a single PDF file.

About PDF File Format

Portable Document Format (PDF) is a type of document created by Adobe back in the 1990s. The purpose of this file format was to introduce a standard for representation of documents and other reference material in a format that is independent of application software, hardware as well as Operating System. PDF files can be opened in Adobe Acrobat Reader/Writer as well in most modern browsers like Chrome, Safari, Firefox via extensions/plug-ins.

Download and Configure

Use the downloads section to download API DLLs or MSI installer or NuGet:

PM> Install-Package GroupDocs.Merger

Source images

“Sample1.jpg” “Sample2.jpg” “Sample3.jpg”

How to merge image files to PDF

The following example demonstrates how to merge image files to PDF file with several lines of C# code:

  • Create an instance of Merger class and pass source image file path as a constructor parameter. You may specify absolute or relative file path as per your requirements. Additionally, pass instance of LoadOptions class as a second constructor parameter.
  • Add another image file to merge with Join method. Repeat this step for other image documents you want to merge.
  • Call Merger class Save method and specify the filename for the merged PDF file as parameter.

// Load the source image file
using (Merger merger = new Merger(@"c:\sample1.jpeg", new LoadOptions(FileType.PDF)))
{
    // Add another image file to merge
    merger.Join(@"c:\sample2.png");
    // Add next image file to merge
    merger.Join(@"c:\sample3.bmp");
    // Merge image files and save PDF result
    merger.Save(@"c:\merged.pdf");
}

Result merged PDF file

“Merged.pdf”

Code Examples

Please find more use-cases and complete C# sources of our backend and frontend examples and try them for free!

Merge PDF Live Demo

GroupDocs.Merger for .NET provides an online Merge Image to PDF App, which allows you to try it for free and check its quality and accuracy.