Document Automation Made Simple

How to Merge PDF Files in C# (.NET) with ConvertAPI – Examples & Tutorial

Learn how to merge PDF files in C# using ConvertAPI. Step-by-step tutorial with code examples for .NET developers. Covers PDF merging, bookmarks, page orientation, page size, and more.

Tomas, CEO

Merging PDF files in C# is a common task for developers building business apps, reporting tools, or document workflows. Whether you want to combine multiple PDFs into one, standardize page layouts, or optimize files, you’ll need a reliable and simple solution.

In this tutorial, we’ll show you how to merge PDFs in C# with ConvertAPI, a powerful cloud-based API that makes PDF merging in .NET quick and easy. We’ll cover the basics and then dive into advanced options like page size, page orientation, bookmarks, and more.

Why Use ConvertAPI for PDF Merging in C#?

ConvertAPI is a file conversion and processing API that supports over 200 formats. For .NET PDF merging, it’s an ideal solution because it:

  • Lets you merge multiple PDF files in C# with minimal code.
  • Works with local files, URLs, or streams.
  • Provides advanced customization like bookmarks and page orientation.
  • Optimizes final output by removing duplicate fonts.
  • Runs in the cloud for speed and scalability.

Whether you’re building a desktop application, a web API, or a batch-processing tool, ConvertAPI simplifies C# PDF merge operations.

Setting Up ConvertAPI in C#

Before merging PDF files, you’ll need to set up the ConvertAPI SDK.

  1. Create a ConvertAPI account and get your API Token.
  2. Install the ConvertAPI .NET SDK from NuGet:
Install-Package ConvertApi

Basic Example: Merge Multiple PDF Files in C#

Here’s the simplest example of how to merge two PDF documents in C#:

using System;
using System.Threading.Tasks;
using ConvertApiDotNet;

class Program
{
    static async Task Main(string[] args)
    {
        var convertApi = new ConvertApi("your-api-token");

        var result = await convertApi.ConvertAsync("pdf", "merge", 
            new ConvertApiFileParam("files", @"C:\Docs\File1.pdf"),
            new ConvertApiFileParam("files", @"C:\Docs\File2.pdf"));

        await result.SaveFilesAsync(@"C:\Docs\Merged.pdf");

        Console.WriteLine("PDFs merged successfully!");
    }
}

This code merges File1.pdf and File2.pdf into a single merged PDF file.

Advanced PDF Merge Options in C#

ConvertAPI also provides advanced options to customize how your merged PDF looks and behaves. These properties let you control page size, orientation, bookmarks, font optimization, and opening page.


PageSize (Scale Pages to Fit a Standard Size)

The PageSize property scales each input page proportionally to fit a target page size such as A4 or Letter. This ensures all pages in the final document are consistent.

var result = await convertApi.ConvertAsync("pdf", "merge", 
    new ConvertApiFileParam("files", @"C:\Docs\File1.pdf"),
    new ConvertApiFileParam("files", @"C:\Docs\File2.pdf"),
    new ConvertApiParam("PageSize", "A4"));

Use this when merging reports or invoices with mixed formats into one standardized PDF file in C#.

PageOrientation (Portrait or Landscape)

The PageOrientation property sets whether the output PDF should be in Portrait or Landscape mode.

var result = await convertApi.ConvertAsync("pdf", "merge", 
    new ConvertApiFileParam("files", @"C:\Docs\File1.pdf"),
    new ConvertApiFileParam("files", @"C:\Docs\File2.pdf"),
    new ConvertApiParam("PageOrientation", "Landscape"));

Ideal for merging wide spreadsheets, diagrams, or presentations into a landscape PDF.

BookmarksToc (Table of Contents with Bookmarks)

The BookmarksToc property automatically generates a clickable table of contents in the merged PDF, making navigation easier.

var result = await convertApi.ConvertAsync("pdf", "merge", 
    new ConvertApiFileParam("files", @"C:\Docs\File1.pdf"),
    new ConvertApiFileParam("files", @"C:\Docs\File2.pdf"),
    new ConvertApiParam("BookmarksToc", "true"));

Useful when merging multiple PDF documents like contracts or chapters into one file.

RemoveDuplicateFonts (Optimize File Size)

The RemoveDuplicateFonts property reduces PDF size by removing redundant embedded fonts.

var result = await convertApi.ConvertAsync("pdf", "merge", 
    new ConvertApiFileParam("files", @"C:\Docs\File1.pdf"),
    new ConvertApiFileParam("files", @"C:\Docs\File2.pdf"),
    new ConvertApiParam("RemoveDuplicateFonts", "true"));

Great for archiving or emailing PDFs where smaller file size matters.

OpenPage (Set Starting Page)

The OpenPage property defines which page should be shown first when the merged PDF opens.

var result = await convertApi.ConvertAsync("pdf", "merge", 
    new ConvertApiFileParam("files", @"C:\Docs\File1.pdf"),
    new ConvertApiFileParam("files", @"C:\Docs\File2.pdf"),
    new ConvertApiParam("OpenPage", "3"));

Perfect for skipping introductory content and jumping directly to the main content page.

Combine Multiple PDF Merge Properties in C#

You can also combine all options in a single C# merge PDF operation:

var result = await convertApi.ConvertAsync("pdf", "merge", 
    new ConvertApiFileParam("files", @"C:\Docs\File1.pdf"),
    new ConvertApiFileParam("files", @"C:\Docs\File2.pdf"),
    new ConvertApiParam("PageSize", "A4"),
    new ConvertApiParam("PageOrientation", "Portrait"),
    new ConvertApiParam("BookmarksToc", "true"),
    new ConvertApiParam("RemoveDuplicateFonts", "true"),
    new ConvertApiParam("OpenPage", "1"));

Conclusion

With ConvertAPI’s C# PDF merge library, you can:

  • Merge multiple PDF files into one.
  • Control page size and orientation.
  • Add bookmarks and navigation.
  • Optimize file size by removing fonts.
  • Choose which page opens first.

This makes it easy to integrate PDF merging in .NET applications for invoicing, reporting, document processing, or archiving.

Try ConvertAPI for free and start merging PDFs in your next C# project today!


Related converters

Ready to Streamline Your File Conversions?