> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/open-save-document/basics/rotate-pdf.md).

# Rotating PDF Pages in Android

Learn how to easily rotate PDF pages using Apryse's library. Rotate pages dialog offers two options for temporary or permanent rotation. Find out more here! The Apryse Android SDK streamlines secure d

{% hint style="info" %}
Apryse's library has a rotate pages dialog which allows users to rotate pages easily. For more information, see: [rotate pages dialog ](/android/page-manipulation/rotate.md#ui-component).
{% endhint %}

There are two options for rotating PDF pages. The first is rotating [`PDFViewCtrl`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html), it will rotate all PDF pages temporarily. The second is rotating PDF pages using [`Page`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Page.html) class, it will rotate selected PDF pages permanently.

## Rotating PDFViewCtrl

If you want to rotate a `PDFViewCtrl` by 90 degrees clockwisely, just simply call [`PDFViewCtrl.rotateClockwise ()`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html#rotateClockwise\(\)). If you want to rotate the `PDFViewCtrl` by 90 degrees **counter clockwisely**, call [`PDFViewCtrl.rotateCounterClockwise ()`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html#rotateCounterClockwise\(\)). After rotation, update the `PDFViewCtrl` pages layout by calling [`PDFViewCtrl.updatePageLayout()`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html#updatePageLayout\(\)).

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
pdfViewCtrl.rotateClockwise();
try {
    pdfViewCtrl.updatePageLayout();
} catch (Exception e) {
    e.printStackTrace();  
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
pdfViewCtrl.rotateClockwise()
try {
    pdfViewCtrl.updatePageLayout()
} catch (e: Exception) {
    e.printStackTrace()
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

where `pdfViewCtrl` is the instance of `PDFViewCtrl`.

## Rotating a PDF page

To rotate a PDF page by 90 degrees, call [`Page.setRotation(int)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Page.html#setRotation\(int\)). The parameter of this method is the rotation value, which is one of \[0, 1, 2, 3]. It represents \[0 degree, 90 degree, 180 degree, 270 degree] correspondingly. After rotation, update the `PDFViewCtrl` pages layout by calling [`PDFViewCtrl.updatePageLayout()`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html#updatePageLayout\(\)).

{% hint style="info" %}
To rotate a PDF page, you must lock `PDFViewCtrl` first, see: [document locking ](/android/open-save-document/lock.md).
{% endhint %}

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
void rotatePage(final PDFViewCtrl pdfViewCtrl, final int pageNum, @IntRange(from = 0, to = 3) final int rotateValue) throws Exception {
    // lock pdf doc
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            // get pdf document
            PDFDoc pdfDoc = pdfViewCtrl.getDoc();
            // get page from page number
            Page page = pdfDoc.getPage(pageNum);
            page.setRotation(rotateValue);
            // update page layout
            pdfViewCtrl.updatePageLayout();
        }
    });
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
fun rotatePage(pdfViewCtrl: PDFViewCtrl, pageNum: Int, @IntRange(from = 0, to = 3) rotateValue: Int) { 
    // lock pdf doc
    pdfViewCtrl.docLock(true) {
        // get pdf document
        val pdfDoc = pdfViewCtrl.doc
        // get page from page number
        val page = pdfDoc.getPage(pageNum)
        page.rotation = rotateValue
        // update page layout
        pdfViewCtrl.updatePageLayout()
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Rotating PDF pages

To rotate PDF pages, traverse each page and call `Page.setRotation(int)`. The following example shows how to rotate all pages of a PDF document.

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
void rotateAllPages(final PDFViewCtrl pdfViewCtrl, @IntRange(from = 0, to = 3) final int rotateValue) throws Exception{
    // lock pdf doc
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            // get pdf document
            PDFDoc pdfDoc = pdfViewCtrl.getDoc();
            // get page iteration
            PageIterator itr = pdfDoc.getPageIterator();
            while (itr.hasNext()) {
                Page page = (Page) itr.next();
                // rotate page
                page.setRotation(rotateValue);
            }
            // update page layout
            pdfViewCtrl.updatePageLayout();
        }
    });
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
fun rotateAllPages(pdfViewCtrl: PDFViewCtrl, @IntRange(from = 0, to = 3) rotateValue: Int) { 
    // lock pdf doc
    pdfViewCtrl.docLock(true) {
        // get pdf document
        val pdfDoc = pdfViewCtrl.doc
        // get page iteration
        val itr = pdfDoc.pageIterator
        while (itr.hasNext()) {
            // rotate page
            itr.next()!!.rotation = rotateValue
        }
        // update page layout
        pdfViewCtrl.updatePageLayout()
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/android/open-save-document/basics/rotate-pdf.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
