Spire.Cloud.PDF provides the PdfDocumentApi interface, which can be used to manipulate the entire document. This article demonstrates how to merge PDFs or split a PDF document by using this API.
Example 1. Merge PDF documents
using System;
using System.Collections.Generic;
using Spire.Cloud.Pdf.Sdk.Api;
using Spire.Cloud.Pdf.Sdk.Client;
namespace MergePDFs
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration pdfConfiguration = new Configuration(appId, appKey, baseUrl);
//Create a PdfDocumentApi object
static PdfDocumentApi pdfDocumentApi = new PdfDocumentApi(pdfConfiguration);
static void Main(string[] args)
{
//Specify resulted file name
string name = "Merged.pdf";
//Specify output file folder
string outFolder = "output";
//Create a List object
List files = new List();
//Add paths of the files to be merged in the list
files.Add("input/test1.pdf");
files.Add("input/test2.pdf");
//Call MergeDocument method to merge files
pdfDocumentApi.MergeDocument(name, files, outFolder);
}
}
}
Example 2. Split PDF document
using System;
using Spire.Cloud.Pdf.Sdk.Api;
using Spire.Cloud.Pdf.Sdk.Client;
namespace SplitPDF
{
class Program
{
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration pdfConfiguration = new Configuration(appId, appKey, baseUrl);
//Create a PdfDocumentApi object
static PdfDocumentApi pdfDocumentApi = new PdfDocumentApi(pdfConfiguration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.pdf";
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Specify the output path
string outPath = "output/";
//Call SplitDocument method to split PDF into one-page PDF documents
pdfDocumentApi.SplitDocument(name, outPath, folder, storage);
}
}
}