Spire.Cloud.PDF API provides the PdfPagesApi interface for developers to manipulate PDF pages. It supports adding/deleting PDF pages, getting the page information including name, page number, property. This article will demonstrate how to add and delete PDF page by using Spire.Cloud.PDF API.
Add Page
import spire.cloud.pdf.sdk.*;
import spire.cloud.pdf.sdk.api.PdfPagesApi;
import spire.cloud.pdf.sdk.model.*;
public class AddPage {
private static String appId = "APP ID";
private 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 PdfPagesApi
PdfPagesApi api = new PdfPagesApi(configuration);
//Specify the name of the input document
String name = "Spire.pdf";
//Specify the storage path and name of the generated document
String destFilePath = "output/AddPage_output.pdf";
//Add a new page and set its height and width
Page page = new Page();
RectangleF rect = new RectangleF();
rect.X(0f);
rect.Y(0f);
rect.width(500f);
rect.height(500f);
page.rect(rect);
//Specify the folder where the input document is stored, set it to null if there's none
String folder = "input";
//Specify the original password of the input document, set it to null if there's none
String password = null;
//Store the document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Add a new page to PDF with the addPage method
api.addPage(name, destFilePath, page, folder, storage, password);
}
}
Delete Page
import spire.cloud.pdf.sdk.*;
import spire.cloud.pdf.sdk.api.PdfPagesApi;
public class deletePage {
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 PdfPagesApi
PdfPagesApi api = new PdfPagesApi(configuration);
//Specify the name of the input document
String name = "Spire.pdf";
//Specify the folder where the input document is stored, set it to null if there's none
String folder = "input";
//Specify the storage path and name of the generated document
String destFilePath = "output/DeletePage_output.pdf";
//The page that need to be deleted
Integer pageNumber = 2;
//Specify the original password of the input document, set it to null if there's none
String password = null;
//Store the document in the 2G default storage space offered by E-iceblue Cloud
String storage = null;
//Delete PDF page with the deletePage method
api.deletePage(name, destFilePath, pageNumber, folder, storage, password);
}
}