Split PDF in .NET SDK

Split Single PDF Pages in C# Cloud API without the use of any software like Adobe PDF.

Get Started

How to Split Single PDF Files Using C# Cloud API

In order to split 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: PM> Install-Package Aspose.Pdf-Cloud

Steps for Splitting 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 splitting
  5. Download the result
 

Split Single PDF File using C#


    public static void SplitSinglePages()
    {
        const string localImageFileName = @"C:\Samples\Sample-Document-01.pdf";
        const string storageFileName = "Sample-Document-01.pdf";
        const string resultFileName = "output-splitted";
        const string localFolder = @"C:\Samples";

        // Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
        var pdfApi = new PdfApi(AppSecret, AppSid);

        if (pdfApi.GetFilesList("").Value.All(f => f.Name != storageFileName))
        {
            using var file = File.OpenRead(localImageFileName);
            var uploadResult = pdfApi.UploadFile(storageFileName, file);
            Console.WriteLine(uploadResult.Uploaded[0]);
        }

        var response = pdfApi.PostSplitDocument(storageFileName);
        uint index = 1;
        foreach (var fileName in response.Result.Documents.Select(document => document.Href))
        {
            using Stream downloadStream = pdfApi.DownloadFile(fileName);
            using FileStream localStream = File.Create(Path.Combine(localFolder, resultFileName + $"-page{index++}.pdf"));
            downloadStream.CopyTo(localStream);
        }
    }