Edit in GitHubLog an issue

Rotate Pages

Rotate a page in an existing document.

Rest API

See our public API Reference for Rotate Pages.

Rotate Pages in PDF

The rotate pages operation selectively rotates pages in PDF file. For example, you can change portrait view to landscape view.

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.rotatepages.RotatePDFPages
public class RotatePDFPages {
// Initialize the logger.
private static final Logger LOGGER = LoggerFactory.getLogger(RotatePDFPages.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);
RotatePagesOperation rotatePagesOperation = RotatePagesOperation.createNew();
// Set operation input from a source file.
FileRef source = FileRef.createFromLocalFile("src/main/resources/rotatePagesInput.pdf");
rotatePagesOperation.setInput(source);
// Sets angle by 90 degrees (in clockwise direction) for rotating the specified pages of
// the input PDF file.
PageRanges firstPageRange = getFirstPageRangeForRotation();
rotatePagesOperation.setAngleToRotatePagesBy(Angle._90, firstPageRange);
// Sets angle by 180 degrees (in clockwise direction) for rotating the specified pages of
// the input PDF file.
PageRanges secondPageRange = getSecondPageRangeForRotation();
rotatePagesOperation.setAngleToRotatePagesBy(Angle._180, secondPageRange);
// Execute the operation.
FileRef result = rotatePagesOperation.execute(executionContext);
// Save the result to the specified location.
result.saveAs("output/rotatePagesOutput.pdf");
} catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {
LOGGER.error("Exception encountered while executing operation", e);
}
}
private static PageRanges getFirstPageRangeForRotation() {
// Specify pages for rotation.
PageRanges firstPageRange = new PageRanges();
// Add page 1.
firstPageRange.addSinglePage(1);
// Add pages 3 to 4.
firstPageRange.addRange(3, 4);
return firstPageRange;
}
private static PageRanges getSecondPageRangeForRotation() {
// Specify pages for rotation.
PageRanges secondPageRange = new PageRanges();
// Add page 2.
secondPageRange.addSinglePage(2);
return secondPageRange;
}
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.