Merge and Combine Multiple Files into a PDF in C#

This guide explains how to merge multiple PDF files into a single PDF file. It also explains how to combine files of different types into a single PDF file. The procedure explained in this guide works for all supported file types.

Merging Multiple PDF Files into a Single PDF File

To create a single PDF file from multiple PDF files, follow these steps:

  1. Create a GdPictureDocumentConverter object.

  2. Add the file paths of the source PDF documents to a list.

  3. Save the output in a new PDF document with the CombineToPDF method. It takes the following parameters:

    • The list of source file paths.

    • The path to the output PDF file.

    • A member of the PdfConformance enumeration that specifies the conformance level of the output PDF file. For example, use PDF to create a common PDF document.

The example below creates a single PDF document from multiple PDF files:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Add the source PDF documents to a list.
IEnumerable<string> sourceFiles = new List<string>(new string[] {
    @"C:\temp\source1.pdf",
    @"C:\temp\source2.pdf",
    @"C:\temp\source3.pdf",
    @"C:\temp\source4.pdf"
});
// Save the output in a new PDF document.
gdpictureDocumentConverter.CombineToPDF(sourceFiles, @"C:\temp\output.pdf", PdfConformance.PDF);
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Add the source PDF documents to a list.
    Dim sourceFiles As IEnumerable(Of String) = New List(Of String)(New String() {"C:\temp\source1.pdf", "C:\temp\source2.pdf", "C:\temp\source3.pdf", "C:\temp\source4.pdf"})
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.CombineToPDF(sourceFiles, "C:\temp\output.pdf", PdfConformance.PDF)
End Using
Used Methods

Related Topics

Combining Files of Different Types into a Single PDF File

To combine files of different types into a single PDF file, follow these steps:

  1. Create a GdPictureDocumentConverter object.

  2. Add the file paths of the source files to a list.

  3. Save the output in a new PDF document with the CombineToPDF method. It takes the following parameters:

    • The list of source file paths.

    • The path to the output PDF file.

    • A member of the PdfConformance enumeration that specifies the conformance level of the output PDF file. For example, use PDF to create a common PDF document.

The example below creates a single PDF document from files of different types:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Add the source files to a list.
IEnumerable<string> sourceFiles = new List<string>(new string[] {
    @"C:\temp\source.png",
    @"C:\temp\source.pdf",
    @"C:\temp\source.tiff",
    @"C:\temp\source.txt"
});
// Save the output in a new PDF document.
gdpictureDocumentConverter.CombineToPDF(sourceFiles, @"C:\temp\output.pdf", PdfConformance.PDF);
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Add the source files to a list.
    Dim sourceFiles As IEnumerable(Of String) = New List(Of String)(New String() {"C:\temp\source.png", "C:\temp\source.pdf", "C:\temp\source.tiff", "C:\temp\source.txt"})
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.CombineToPDF(sourceFiles, "C:\temp\output.pdf", PdfConformance.PDF)
End Using
Used Methods

Related Topics