PNG JPG BMP TIFF PDF
Aspose.PDF  for .NET

Merge PDF in .NET SDK

Merge two PDF files into one in C# Cloud API without the use of any software like Adobe PDF.

Get Started

How to Merge Multiple PDF Files Using C# Cloud API

In order to merge two PDF files we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Command


PM> Install-Package Aspose.Pdf-Cloud 

Steps for Merging PDF via Cloud .NET SDK

A basic merging pdfs programmatically with Aspose.PDF Cloud .NET SDK APIs can be done with just few lines of code.

  1. Create a new Configuration object with your Application Secret and Key
  2. Create an object to connect to the Cloud API
  3. Upload your document file
  4. Perform the merging
  5. Download the result
 

Merge Two PDF Files using C#


    internal static void MergePdf()
    {
        const string localImageFileName = @"C:\Samples\sample.pdf";
        const string storageFileName1 = "sample1.pdf";
        const string storageFileName2 = "sample2.pdf";
        const string resultFileName = "merged-doc.pdf";

        // Get your AppSid and AppSecret https://dashboard.aspose.cloud (free registration required).
        var pdfApi = new PdfApi(AppSecret, AppSid);
        using var file = File.OpenRead(localImageFileName);
        pdfApi.UploadFile(storageFileName1, file);
        pdfApi.CopyFile(storageFileName1, storageFileName2);

        var documentsToBeMerged = new List<string>()
        {
            storageFileName1, storageFileName2
        };

        var documents = new Aspose.Pdf.Cloud.Sdk.Model.MergeDocuments(documentsToBeMerged);
        
        pdfApi.PutMergeDocuments(resultFileName, documents);
        var response = pdfApi.DownloadFile(resultFileName);
        response.CopyTo(File.OpenWrite(resultFileName));
        Console.WriteLine();
    }