Rotate PDF Pages
Use the Page.setRotation(PageRotationAngle rotation) method to rotate a page by the specified angle. This method changes the page orientation without modifying the page content.
The following code snippet rotates all pages in a PDF document 90 degrees clockwise and saves the result to a new PDF file:
import com.devexpress.docs.pdf.*;
import java.nio.channels.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (PdfDocument pdfDocument = new PdfDocument(FileChannel.open(
Path.of("document.pdf")))) {
// Rotate all pages 90 degrees clockwise.
for(Page page : pdfDocument.getPages()) {
page.setRotation(PageRotationAngle.CLOCKWISE_90);
}
// Save the document to a PDF file.
try (WritableByteChannel writableByteChannel =
FileChannel.open(Path.of("result.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(writableByteChannel);
}
}
}
}