Merge PDF documents programmatically
ConvertAPI provides a PDF Merge tool available as a REST API service. We crafted a .NET wrapper library for simple and convenient integration into your project. It is accessible via a NuGet package manager, and the source code can be found on GitHub. Simply sign up for a free account, grab your API secret key, install our .NET library, and you are good to go!
Install the ConvertAPI library into the .NET project
To install our SDK into your project, simply run this command from the NuGet console:
PM> Install-Package ConvertApi
Or search for the ConvertApi
package in the NuGet package explorer.
Merge PDF files using C#
Once you have the library installed, you can use this code example showing how to merge multiple PDF files using C# programming language:
using System;
using System.Threading.Tasks;
using ConvertApiDotNet;
using ConvertApiDotNet.Exceptions;
namespace ConvertAPILibrary
{
class Program
{
static async Task Main(string[] args)
{
try
{
// Code snippet is using the ConvertAPI C# Client: https://github.com/ConvertAPI/convertapi-dotnet
// Read more about PDF Merge API: https://www.convertapi.com/pdf-to-merge
var convertApi = new ConvertApi("your-api-secret");
var convert = await convertApi.ConvertAsync("pdf", "merge",
new ConvertApiFileParam("Files", @"C:\path\to\sample-1.pdf"),
new ConvertApiFileParam("Files", @"C:\path\to\sample-2.pdf"),
new ConvertApiFileParam("Files", @"C:\path\to\sample-3.pdf")
);
var saveFiles = await convert.SaveFilesAsync(@"C:\converted-files\");
Console.WriteLine("The PDF saved to " + saveFiles);
}
catch (ConvertApiException e)
{
Console.WriteLine("Status Code: " + e.StatusCode);
Console.WriteLine("Response: " + e.Response);
}
}
}
}
That's all it takes to implement a PDF merge functionality into the .NET project. You can combine local PDF files together with the files hosted on a server accessible via the URL, or the files uploaded to our server accessible by FileId.
Advanced techniques
You can find a complete list of conversion parameters on our interactive demo tool page. More advanced techniques and examples can be found in our GitHub examples folder. Happy coding!