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

# Imposition

Sample Java code for using Apryse SDK to impose (combine) multiple PDF pages. Page imposition can be used to arrange/order pages prior to printing or for document assembly (assemble a 'master' page fr

Sample Java code for using Apryse SDK to impose (combine) multiple PDF pages. Page imposition can be used to arrange/order pages prior to printing or for document assembly (assemble a 'master' page from several 'source' pages). It is also possible to write applications that can re-order the pages such that they will display in the correct order when the hard copy pages are compiled and folded correctly. 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.Element;
import com.pdftron.pdf.ElementBuilder;
import com.pdftron.pdf.ElementWriter;
import com.pdftron.pdf.PDFDoc;
import com.pdftron.pdf.Page;
import com.pdftron.pdf.PageIterator;
import com.pdftron.pdf.Rect;
import com.pdftron.sdf.SDFDoc;

import java.util.ArrayList;

//-----------------------------------------------------------------------------------
//The sample illustrates how multiple pages can be combined/imposed
//using PDFNet. Page imposition can be used to arrange/order pages
//prior to printing or to assemble a 'master' page from several 'source'
//pages. Using PDFNet API it is possible to write applications that can
//re-order the pages such that they will display in the correct order
//when the hard copy pages are compiled and folded correctly.
//-----------------------------------------------------------------------------------

public class ImpositionTest extends PDFNetSample {

	private static OutputListener mOutputListener;

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

    public ImpositionTest() {
        setTitle(R.string.sample_imposition_title);
        setDescription(R.string.sample_imposition_description);
    }

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

        String filein = Utils.getAssetTempFile(INPUT_PATH + "newsletter.pdf").getAbsolutePath();
        String fileout = Utils.createExternalFile("newsletter_booklet.pdf", mFileList).getAbsolutePath();

        mOutputListener.println("-------------------------------------------------");
        mOutputListener.println("Opening the input pdf...");
        try (PDFDoc in_doc = new PDFDoc(filein)) {
            in_doc.initSecurityHandler();

            // Create a list of pages to import from one PDF document to another.
            Page[] copy_pages = new Page[in_doc.getPageCount()];
            int j = 0;
            for (PageIterator itr = in_doc.getPageIterator(); itr.hasNext(); j++) {
                copy_pages[j] = itr.next();
            }

            try (PDFDoc new_doc = new PDFDoc()) {
                Page[] imported_pages = new_doc.importPages(copy_pages);

                // Paper dimension for A3 format in points. Because one inch has
                // 72 points, 11.69 inch 72 = 841.69 points
                Rect media_box = new Rect(0, 0, 1190.88, 841.69);
                double mid_point = media_box.getWidth() / 2;

                ElementBuilder builder = new ElementBuilder();
                ElementWriter writer = new ElementWriter();

                for (int i = 0; i < imported_pages.length; ++i) {
                    // Create a blank new A3 page and place on it two pages from the input document.
                    Page new_page = new_doc.pageCreate(media_box);
                    writer.begin(new_page);

                    // Place the first page
                    Page src_page = imported_pages[i];
                    Element element = builder.createForm(src_page);

                    double sc_x = mid_point / src_page.getPageWidth();
                    double sc_y = media_box.getHeight() / src_page.getPageHeight();
                    double scale = sc_x < sc_y ? sc_x : sc_y; // min(sc_x, sc_y)
                    element.getGState().setTransform(scale, 0, 0, scale, 0, 0);
                    writer.writePlacedElement(element);

                    // Place the second page
                    ++i;
                    if (i < imported_pages.length) {
                        src_page = imported_pages[i];
                        element = builder.createForm(src_page);
                        sc_x = mid_point / src_page.getPageWidth();
                        sc_y = media_box.getHeight() / src_page.getPageHeight();
                        scale = sc_x < sc_y ? sc_x : sc_y; // min(sc_x, sc_y)
                        element.getGState().setTransform(scale, 0, 0, scale, mid_point, 0);
                        writer.writePlacedElement(element);
                    }

                    writer.end();
                    new_doc.pagePushBack(new_page);
                }

                new_doc.save(fileout, SDFDoc.SaveMode.LINEARIZED, null);
                mOutputListener.println("Done. Result saved in newsletter_booklet.pdf...");
            }
        } 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.*
import com.pdftron.sdf.SDFDoc
import java.util.*

//-----------------------------------------------------------------------------------
//The sample illustrates how multiple pages can be combined/imposed
//using PDFNet. Page imposition can be used to arrange/order pages
//prior to printing or to assemble a 'master' page from several 'source'
//pages. Using PDFNet API it is possible to write applications that can
//re-order the pages such that they will display in the correct order
//when the hard copy pages are compiled and folded correctly.
//-----------------------------------------------------------------------------------

class ImpositionTest : PDFNetSample() {
    init {
        setTitle(R.string.sample_imposition_title)
        setDescription(R.string.sample_imposition_description)
    }

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

        val filein = Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + "newsletter.pdf")!!.absolutePath
        val fileout = Utils.createExternalFile("newsletter_booklet.pdf", mFileList).absolutePath

        mOutputListener!!.println("-------------------------------------------------")
        mOutputListener!!.println("Opening the input pdf...")
        try {
            PDFDoc(filein).use { in_doc ->
                in_doc.initSecurityHandler()

                // Create a list of pages to import from one PDF document to another.
                val copy_pages = arrayOfNulls<Page>(in_doc.pageCount)
                var j = 0
                val itr = in_doc.pageIterator
                while (itr.hasNext()) {
                    copy_pages[j] = itr.next()
                    j++
                }

                PDFDoc().use { new_doc ->
                    val imported_pages = new_doc.importPages(copy_pages)

                    // Paper dimension for A3 format in points. Because one inch has
                    // 72 points, 11.69 inch 72 = 841.69 points
                    val media_box = Rect(0.0, 0.0, 1190.88, 841.69)
                    val mid_point = media_box.width / 2

                    val builder = ElementBuilder()
                    val writer = ElementWriter()

                    var i = 0
                    while (i < imported_pages.size) {
                        // Create a blank new A3 page and place on it two pages from the input document.
                        val new_page = new_doc.pageCreate(media_box)
                        writer.begin(new_page)

                        // Place the first page
                        var src_page = imported_pages[i]
                        var element = builder.createForm(src_page)

                        var sc_x = mid_point / src_page.pageWidth
                        var sc_y = media_box.height / src_page.pageHeight
                        var scale = if (sc_x < sc_y) sc_x else sc_y // min(sc_x, sc_y)
                        element.gState.setTransform(scale, 0.0, 0.0, scale, 0.0, 0.0)
                        writer.writePlacedElement(element)

                        // Place the second page
                        ++i
                        if (i < imported_pages.size) {
                            src_page = imported_pages[i]
                            element = builder.createForm(src_page)
                            sc_x = mid_point / src_page.pageWidth
                            sc_y = media_box.height / src_page.pageHeight
                            scale = if (sc_x < sc_y) sc_x else sc_y // min(sc_x, sc_y)
                            element.gState.setTransform(scale, 0.0, 0.0, scale, mid_point, 0.0)
                            writer.writePlacedElement(element)
                        }

                        writer.end()
                        new_doc.pagePushBack(new_page)
                        ++i
                    }

                    new_doc.save(fileout, SDFDoc.SaveMode.LINEARIZED, null)
                    mOutputListener!!.println("Done. Result saved in newsletter_booklet.pdf...")
                }
            }
        } 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 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/get-started/samples/impositiontest.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.
