Skip to content
ComPDF
Guides

Rotate Pages

Rotate the display orientation of specified pages, supporting 90-degree clockwise and counterclockwise rotation.

Using CPDFReaderWidget:

dart
CPDFReaderWidgetController? _controller;
// Initialize CPDFReaderWidget and get controller in onCreated callback
CPDFReaderWidget(
  document: documentPath,
  configuration: CPDFConfiguration(),
  onCreated: (controller) {
    setState(() {
      this._controller = controller;
    });
  },
);

// Rotate the first page
    const pageIndex = 0;
    final page = controller.document.pageAtIndex(pageIndex);
    final currentRotation = await page.getRotation();
    final newAngle = currentRotation + 90;

    final result = await page.setRotation(newAngle);
    // Refresh pages after success
    if (result) {
      controller.reloadPages();
    }

Using CPDFDocument:

dart
// Create and open the document
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
  // Rotate the first page
      const pageIndex = 0;
      final page = document.pageAtIndex(pageIndex);
      final currentRotation = await page.getRotation();
      final newAngle = currentRotation + 90; 
      final result = await page.setRotation(newAngle);
}