Edit in GitHubLog an issue

Delete Pages

Delete one or more pages from a document

Rest API

See our public API Reference for Delete Pages

Delete Pages in a PDF

The delete pages operation selectively removes pages from a PDF 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.deletepages.DeletePDFPages
public class DeletePDFPages {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(DeletePDFPages.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);
DeletePagesOperation deletePagesOperation = DeletePagesOperation.createNew();
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/deletePagesInput.pdf");
deletePagesOperation.setInput(source);
// Delete pages of the document (as specified by PageRanges).
PageRanges pageRangeForDeletion = getPageRangeForDeletion();
deletePagesOperation.setPageRanges(pageRangeForDeletion);
// Execute the operation.
FileRef result = deletePagesOperation.execute(executionContext);
// Save the result to the specified location.
result.saveAs("output/deletePagesOutput.pdf");
} catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
private static PageRanges getPageRangeForDeletion() {
// Specify pages for deletion.
PageRanges pageRangeForDeletion = new PageRanges();
// Add page 1.
pageRangeForDeletion.addSinglePage(1);
// Add pages 3 to 4.
pageRangeForDeletion.addRange(3, 4);
return pageRangeForDeletion;
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.