Rotate PDF Pages in Java
Contents
[
Hide
]
Use the page rotation API when you need to change orientation across one or more pages.
Rotate all pages by 90 degrees
Use this example when every page in the document should be rotated clockwise.
- Open the source PDF Document.
- Iterate through all Page objects and set the rotation value.
- Save the updated PDF.
public static void rotatePage(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
for (Page page : document.getPages()) {
page.setRotate(Rotation.on90);
}
document.save(outputFile.toString());
}
}