Edit in GitHubLog an issue

Reorder Pages

Reorder the pages of a PDF file to reorganize.

Rest API

See our public API Reference for Reorder Pages

Reorder Pages in PDF

The reorder pages operation moves pages from one location to another in 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.reorderpages.ReorderPDFPages
public class ReorderPDFPages {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(ReorderPDFPages.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);
ReorderPagesOperation reorderPagesOperation = ReorderPagesOperation.createNew();
// Set operation input from a source file, along with specifying the order of the pages for
// rearranging the pages in a PDF file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/reorderPagesInput.pdf");
PageRanges pageRanges = getPageRangeForReorder();
reorderPagesOperation.setInput(source);
reorderPagesOperation.setPagesOrder(pageRanges);
// Execute the operation.
FileRef result = reorderPagesOperation.execute(executionContext);
// Save the result to the specified location.
result.saveAs("output/reorderPagesOutput.pdf");
} catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
private static PageRanges getPageRangeForReorder() {
// Specify order of the pages for an output document.
PageRanges pageRanges = new PageRanges();
// Add pages 3 to 4.
pageRanges.addRange(3, 4);
// Add page 1.
pageRanges.addSinglePage(1);
return pageRanges;
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.