> 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/crop-pages.md).

# Cropping PDF pages in Android

Cropping PDF pages in Android is easy with the Apryse library, you can crop pages manually or automatically, as well as reset document pages to their original size. The UserCropDialogFragment allows a

With the Apryse library you can crop pages manually or automatically, as well as reset document pages to their original size. The [`UserCropDialogFragment`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/UserCropDialogFragment.html) allows a user to adjust the page's crop box which can then be applied to a subset of pages or to all the pages in a document.

![](https://226546913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0QItsdFBmuuL9ezHimHy%2Fuploads%2Fgit-blob-829d16c6a0dd2a2b5a4590c036eb396908a49aeb%2Fbe20e1f5d7b00edf611f9ef5a75f79ddedd90f7c-600x1200.gif?alt=media)

## Show user crop pages dialog

To show a user crop pages dialog in your activity, create a new instance of [`UserCropDialogFragment`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/controls/UserCropDialogFragment.html) by calling `newInstance()` and setting the [`PDFViewCtrl`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html):

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

```java
private PDFViewCtrl mPdfViewCtrl;
// ...
public void showUserCropDialog(FragmentManager fragmentManager) {
    UserCropDialogFragment fragment = UserCropDialogFragment.newInstance();
    fragment.setPdfViewCtrl(mPdfViewCtrl);
    // Set a custom style for this dialog
    fragment.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.PDFTronAppTheme);
    // Show the dialog
    fragment.show(fragmentManager, "user_crop_pages_dialog");
}
```

{% endcode %}
{% endtab %}

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

```kotlin
private var mPdfViewCtrl: PDFViewCtrl? = null
// ...
fun showUserCropDialog(fragmentManager: FragmentManager) {
    val fragment = UserCropDialogFragment.newInstance()
    fragment.setPdfViewCtrl(mPdfViewCtrl!!)
    // Set a custom style for this dialog
    fragment.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.PDFTronAppTheme)
    // Show the dialog
    fragment.show(fragmentManager, "user_crop_pages_dialog")
}
```

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

In order to view user cropped pages in [`PDFViewCtrl`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html) make sure you set `Page.e_user_crop` as the default page box:

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

```java
mPdfViewCtrl.setPageBox(Page.e_user_crop);
```

{% endcode %}
{% endtab %}

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

```kotlin
mPdfViewCtrl?.setPageBox(Page.e_user_crop)
```

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

You can also set a listener via [`setOnUserCropDialogDismissListener(...)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html) to be notified when the user crop dialog is dismissed.

{% hint style="info" %}
`UserCropDialogFragment` does not crop pages permanently, it may not handled well by other PDF viewer. To crop pages permanently, see [cropping pages permanently](https://docs.apryse.com)
{% endhint %}

## Automatically crop pages

You can also automatically crop the edges of the document based on the position of the content. To do this, you can simply call the utility method [`UserCropUtilities.AutoCropInBackgroundTask`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/utils/UserCropUtilities.AutoCropInBackgroundTask.html) and pass in your activity and [`PDFViewCtrl`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html).

**Example**

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

```java
UserCropUtilities.AutoCropInBackgroundTask autoCropTask =
    new UserCropUtilities.AutoCropInBackgroundTask(getContext(), mPdfViewCtrl,
        new UserCropUtilities.AutoCropInBackgroundTask.AutoCropTaskListener() {
            @Override
            public void onAutoCropTaskDone() {
                // Auto crop task was finished or cancelled
            }
        });
```

{% endcode %}
{% endtab %}

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

```kotlin
val autoCropTask = UserCropUtilities.AutoCropInBackgroundTask(context, mPdfViewCtrl,
    UserCropUtilities.AutoCropInBackgroundTask.AutoCropTaskListener {
        // Auto crop task was finished or cancelled
    })
```

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

## Remove user defined crop boxes

If you wish to remove user defined cropping for a given page you can call the utility method [`UserCropUtilities.removeUserCropFromPage(Page)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/utils/UserCropUtilities.html#removeUserCropFromPage\(Page\)).

## Permanently crop pages

Cropping pages using the above methods are at user-level. User-level page-cropping may not be handled well by other PDF viewers. To apply crop pages permanently use [`UserCropUtilities.cropDoc(PDFDoc)`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/utils/UserCropUtilities.html#cropDoc\(PDFDoc\)).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
