Blog

Back to blog posts

Merge PDFs together with C# and .NET Core

Published Nov 18, 2018

Intro

In this article we are going to cover how to merge PDFs together with C# and .NET Core with just a few lines of code using the Api2Pdf dotnet client library. Api2Pdf is a REST API that makes it super easy to generate and combine PDFs. You can view the full documentation of the dotnet client library on Github here, but here we will only focus on merging PDFs together.

Step 1 – Installation

Run the nuget command

Install-Package Api2Pdf

Step 2 – Grab an API Key

In order to use the Api2Pdf merge endpoints, you must first acquire an API key. Register at https://portal.api2pdf.com to get your API key. It only takes a minute.

Step 3 – Write your code

Replace “YOUR-API-KEY” with the key you acquired from Step 2. Grab some URLs to existing PDFs and place them in the list, using the sample code below. If you do not have any links to PDFs handy, you can use the two below:

http://www.api2pdf.com/wp-content/uploads/2018/11/b82dee70-e6e4-11e8-9744-7936761eca6f.pdf

http://www.api2pdf.com/wp-content/uploads/2018/11/e51b48f0-e6e5-11e8-ac0c-b90d0913ce75.pdf

var a2pClient = new Api2Pdf("YOUR-API-KEY");
var links_to_pdfs = new List() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
var apiResponse = a2pClient.Merge(links_to_pdfs);

Print your apiResponse to see the result. The url to your PDF will be in the Pdf attribute of the response object.

That’s it! Merging PDFs together only took a few minutes and required no complicated tools.