Edit in GitHubLog an issue

Split PDF

Split a PDF document into multiple smaller documents by simply specifying either the number of files, pages per file, or page ranges.

Rest API

See our public API Reference for Split PDF.

Split PDF by number of pages

This operation splits a PDF into multiple smaller documents. Simply use the page count to specify the maximum number of pages of each output file.

Please refer the API usage guide to understand how to use our APIs.

Copied to your clipboard
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.splitpdf.SplitPDFByNumberOfPages
public class SplitPDFByNumberOfPages {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(SplitPDFByNumberOfPages.class);
public static void main(String[] args) {
try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
SplitPDFOperation splitPDFOperation = SplitPDFOperation.createNew();
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/splitPDFInput.pdf");
splitPDFOperation.setInput(source);
// Set the maximum number of pages each of the output files can have.
splitPDFOperation.setPageCount(2);
// Execute the operation.
List result = splitPDFOperation.execute(executionContext);
// Save the result to the specified location.
int index = 0;
for (FileRef fileRef : result) {
fileRef.saveAs("output/SplitPDFByNumberOfPagesOutput_" + index + ".pdf");
index++;
}
} catch (IOException| ServiceApiException | SdkException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
}

Split PDF by page ranges

As an alternative to creating smaller PDFs with a set number of pages, you can split PDFs into multiple smaller documents by specifying page ranges where each page range corresponds to a single output file.

Please refer the API usage guide to understand how to use our APIs.

Copied to your clipboard
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.splitpdf.SplitPDFByPageRanges
public class SplitPDFByPageRanges {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(SplitPDFByPageRanges.class);
public static void main(String[] args) {
try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
SplitPDFOperation splitPDFOperation = SplitPDFOperation.createNew();
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/splitPDFInput.pdf");
splitPDFOperation.setInput(source);
// Set the page ranges where each page range corresponds to a single output file.
PageRanges pageRanges = getPageRanges();
splitPDFOperation.setPageRanges(pageRanges);
// Execute the operation.
List result = splitPDFOperation.execute(executionContext);
// Save the result to the specified location.
int index = 0;
for (FileRef fileRef : result) {
fileRef.saveAs("output/SplitPDFByPageRangesOutput_" + index + ".pdf");
index++;
}
} catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
private static PageRanges getPageRanges() {
// Specify page ranges.
PageRanges pageRanges = new PageRanges();
// Add page 1.
pageRanges.addSinglePage(1);
// Add pages 3 to 4.
pageRanges.addRange(3, 4);
return pageRanges;
}
}

Split PDF into number of files

As an alternative to creating smaller PDFs by specifying a set number of pages or a page range, you can split PDFs by file count. In this case, the operation creates the specified number of files with each containing an identical number of pages (if possible).

Please refer the API usage guide to understand how to use our APIs.

Copied to your clipboard
// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
// Run the sample:
// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.splitpdf.SplitPDFIntoNumberOfFiles
public class SplitPDFIntoNumberOfFiles {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(SplitPDFIntoNumberOfFiles.class);
public static void main(String[] args) {
try {
// Initial setup, create credentials instance.
Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()
.withClientId("PDF_SERVICES_CLIENT_ID")
.withClientSecret("PDF_SERVICES_CLIENT_SECRET")
.build();
// Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.create(credentials);
SplitPDFOperation splitPDFOperation = SplitPDFOperation.createNew();
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/splitPDFInput.pdf");
splitPDFOperation.setInput(source);
// Set the number of documents to split the input PDF file into.
splitPDFOperation.setFileCount(2);
// Execute the operation.
List result = splitPDFOperation.execute(executionContext);
// Save the result to the specified location.
int index = 0;
for (FileRef fileRef : result) {
fileRef.saveAs("output/SplitPDFIntoNumberOfFilesOutput_" + index + ".pdf");
index++;
}
} catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.