This article will demonstrate how to merge and split PDF documents with the PdfDocumentApi interface provided by Spire.Cloud.PDF API.
Merge PDF documents
import spire.cloud.pdf.sdk.ApiException;
import spire.cloud.pdf.sdk.Configuration;
import spire.cloud.pdf.sdk.api.PdfDocumentApi;
import java.util.ArrayList;
import java.util.List;
public class MergePDFs {
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl= "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
//Create a Configuration object based on App ID, App Key and base Url
Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create an instance of PdfDocumentApi
PdfDocumentApi pdfDocumentApi = new PdfDocumentApi(configuration);
//Add the PDF documents that need to be merged to the list
List files = new ArrayList();
files.add("input/file1.pdf");
files.add("input/file2.pdf");
//Specify the name of the generated document
String name = "MergeDocument.pdf";
//Specify the storage path of the generated document
String folder = "output";
//Store the document in the 2G default storage space offered by E-iceblue Cloud
String storage= null;
//Merge PDF documents with "MergeDocument" method
pdfDocumentApi.mergeDocument(name, files, folder, storage);
}
}
Split PDF document
import spire.cloud.pdf.sdk.ApiException;
import spire.cloud.pdf.sdk.Configuration;
import spire.cloud.pdf.sdk.api.PdfDocumentApi;
public class SplitPDFs {
private static String appId = "APP ID";
private static String appKey = "APP Key";
private static String baseUrl = "https://api.cloudxdocs.com";
public static void main(String[] args) throws ApiException {
//Create a Configuration object based on App ID, App Key and base Url
Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create an instance of PdfDocumentApi
PdfDocumentApi pdfDocumentApi = new PdfDocumentApi(configuration);
//Specify the name of the input PDF document
String name = "input.pdf";
//Specify the folder where the input PDF document is stored, set it to null if there's none
String inputFolder = "input";
//Store the document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Specify the storage path of the generated document
String outFolder = "output/split";
//Split PDF document with the "splitDocument" method
pdfDocumentApi.splitDocument(name, outFolder, inputFolder, storage);
}
}