> 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/get-started/samples/recttest.md).

# Rect

Sample Java code for using Apryse SDK to change a page's MediaBox using Rect class.

Sample Java code for using Apryse SDK to change a page's MediaBox using Rect class. Learn more about our [Android SDK](/core/get-started/languages/java.md) and [PDF Editing & Manipulation Library](/core/page-manipulation/manipulation.md).

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

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

package com.pdftron.android.pdfnetsdksamples.samples;

import com.pdftron.android.pdfnetsdksamples.OutputListener;
import com.pdftron.android.pdfnetsdksamples.PDFNetSample;
import com.pdftron.android.pdfnetsdksamples.R;
import com.pdftron.android.pdfnetsdksamples.util.Utils;
import com.pdftron.pdf.PDFDoc;
import com.pdftron.pdf.PageIterator;
import com.pdftron.pdf.Rect;
import com.pdftron.sdf.SDFDoc;

import java.util.ArrayList;

public class RectTest extends PDFNetSample {

	private static OutputListener mOutputListener;

	private static ArrayList<String> mFileList = new ArrayList<>();

    public RectTest() {
        setTitle(R.string.sample_rect_title);
        setDescription(R.string.sample_rect_description);
    }

	@Override
	public void run(OutputListener outputListener) {
		super.run(outputListener);
		mOutputListener = outputListener;
		mFileList.clear();
		printHeader(outputListener);

        try (PDFDoc input_doc = new PDFDoc((Utils.getAssetTempFile(INPUT_PATH + "tiger.pdf").getAbsolutePath()))) // Test  - Adjust the position of content within the page.
        {
            mOutputListener.println("_______________________________________________");
            mOutputListener.println("Opening the input pdf...");

            input_doc.initSecurityHandler();

            PageIterator pg_itr1 = input_doc.getPageIterator();

            Rect media_box = pg_itr1.next().getMediaBox();

            media_box.setX1(media_box.getX1() - 200);    // translate the page 200 units (1 uint = 1/72 inch)
            media_box.setX2(media_box.getX2() - 200);

            media_box.update();

            input_doc.save(Utils.createExternalFile("tiger_shift.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.NO_FLAGS, null);
            mOutputListener.println("Done. Result saved in tiger_shift...");
        } catch (Exception e) {
            mOutputListener.printError(e.getStackTrace());
        }

		for (String file : mFileList) {
			addToFileList(file);
		}
		printFooter(outputListener);
	}

}
```

{% endcode %}
{% endtab %}

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

```kotlin
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

package com.pdftron.android.pdfnetsdksamples.samples

import com.pdftron.android.pdfnetsdksamples.OutputListener
import com.pdftron.android.pdfnetsdksamples.PDFNetSample
import com.pdftron.android.pdfnetsdksamples.R
import com.pdftron.android.pdfnetsdksamples.util.Utils
import com.pdftron.pdf.PDFDoc
import com.pdftron.sdf.SDFDoc
import java.util.*

class RectTest : PDFNetSample() {
    init {
        setTitle(R.string.sample_rect_title)
        setDescription(R.string.sample_rect_description)
    }

    override fun run(outputListener: OutputListener?) {
        super.run(outputListener)
        mOutputListener = outputListener
        mFileList.clear()
        printHeader(outputListener!!)

        try
        // Test  - Adjust the position of content within the page.
        {
            mOutputListener!!.println("_______________________________________________")
            mOutputListener!!.println("Opening the input pdf...")

            PDFDoc(Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "tiger.pdf")!!.absolutePath).use { input_doc ->
                input_doc.initSecurityHandler()

                val pg_itr1 = input_doc.pageIterator

                val media_box = pg_itr1.next()!!.getMediaBox()

                media_box.x1 = media_box.x1 - 200    // translate the page 200 units (1 uint = 1/72 inch)
                media_box.x2 = media_box.x2 - 200

                media_box.update()

                input_doc.save(Utils.createExternalFile("tiger_shift.pdf", mFileList).absolutePath, SDFDoc.SaveMode.NO_FLAGS, null)
                mOutputListener!!.println("Done. Result saved in tiger_shift...")
            }
        } catch (e: Exception) {
            mOutputListener!!.printError(e.stackTrace)
        }

        for (file in mFileList) {
            addToFileList(file)
        }
        printFooter(outputListener)
    }

    companion object {

        private var mOutputListener: OutputListener? = null

        private val mFileList = ArrayList<String>()
    }

}
```

{% 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 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/get-started/samples/recttest.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.
