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

# Imposition

Sample Obj-C 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 f

Sample Obj-C 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 [iOS SDK](/ios/guides.md) and [PDF Editing & Manipulation Library](/core/page-manipulation/manipulation.md).

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#import <OBJC/PDFNetOBJC.h>
#import <Foundation/Foundation.h>

//-----------------------------------------------------------------------------------
// 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. 
//-----------------------------------------------------------------------------------

int main(int argc, char *argv[])
{
    @autoreleasepool {
        int ret = 0;
        [PTPDFNet Initialize: 0];

        // Relative path to the folder containing test files.
        NSString *input_path = @"../../TestFiles/newsletter.pdf";
        NSString *output_path = @"../../TestFiles/Output/newsletter_booklet.pdf";

        @try
        { 
            NSLog(@"-------------------------------------------------");
            NSLog(@"Opening the input pdf...");

            NSString *filein = input_path;
            NSString *fileout = output_path;

            PTPDFDoc *in_doc = [[PTPDFDoc alloc] initWithFilepath: filein];
            [in_doc InitSecurityHandler];

            // Create a list of pages to import from one PDF document to another.
            PTVectorPage *import_pages = [[PTVectorPage alloc] init];
            PTPageIterator *itr;
            for (itr=[in_doc GetPageIterator: 1]; [itr HasNext]; [itr Next]) {
                [import_pages add: [itr Current]];
            }

            PTPDFDoc *new_doc = [[PTPDFDoc alloc] init];
            PTVectorPage *imported_pages = [new_doc ImportPages: import_pages import_bookmarks: NO];

            // Paper dimension for A3 format in points. Because one inch has 
            // 72 points, 11.69 inch 72 = 841.69 points
            PTPDFRect * media_box = [[PTPDFRect alloc] initWithX1: 0 y1: 0 x2: 1190.88 y2: 841.69]; 
            double mid_point = [media_box Width]/2;

            PTElementBuilder *builder = [[PTElementBuilder alloc] init];
            PTElementWriter *writer = [[PTElementWriter alloc] init];
        
            size_t i;
            for (i=0; i<[imported_pages size]; ++i)
            {
                // Create a blank new A3 page and place on it two pages from the input document.
                PTPage *new_page = [new_doc PageCreate: media_box];
                [writer WriterBeginWithPage: new_page placement: e_ptoverlay page_coord_sys: YES compress: YES resources: NULL];

                // Place the first page
                PTPage *src_page = [imported_pages get:(int)i];
                PTElement *element = [builder CreateFormWithPage: src_page];

                double sc_x = mid_point / [src_page GetPageWidth: e_ptcrop];
                double sc_y = [media_box Height] / [src_page GetPageHeight: e_ptcrop];
                double scale = sc_x < sc_y ? sc_x : sc_y; // min(sc_x, sc_y)
                [[element GetGState] SetTransform: scale b: 0 c: 0 d: scale h: 0 v: 0];
                [writer WritePlacedElement: element];
                
                // Place the second page
                ++i; 
                if (i<[imported_pages size]) {
                    src_page = [imported_pages get:(int)i];
                    element = [builder CreateFormWithPage: src_page];
                    sc_x = mid_point / [src_page GetPageWidth: e_ptcrop];
                    sc_y = [media_box Height] / [src_page GetPageHeight: e_ptcrop];
                    scale = sc_x < sc_y ? sc_x : sc_y; // min(sc_x, sc_y)
                    [[element GetGState] SetTransform: scale b: 0 c: 0 d: scale h: mid_point v: 0];
                    [writer WritePlacedElement: element];
                }

                [writer End];
                [new_doc PagePushBack: new_page];
            }

            [new_doc SaveToFile: fileout flags: e_ptlinearized ];
            NSLog(@"Done. Result saved in newsletter_booklet.pdf...");
        }
        @catch(NSException *e)
        {
            NSLog(@"%@", e.reason);
            ret = 1;
        }
        [PTPDFNet Terminate: 0];        
        return ret;
    }
}
```

{% endcode %}
{% endtab %}

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

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

import PDFNet
import Foundation

//-----------------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------------
func runImpositionTest() -> Int {
    return autoreleasepool {
        var ret: Int = 0
        
        
        // Relative path to the folder containing test files.
        let input_path: String? = Bundle.main.path(forResource: "newsletter", ofType: "pdf")
        let output_path: String = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("newsletter_booklet.pdf").path
        
        do {
            try PTPDFNet.catchException {
                print("-------------------------------------------------")
                print("Opening the input pdf...")
                
                let filein: String? = input_path
                let fileout: String = output_path
                
                let in_doc: PTPDFDoc = PTPDFDoc(filepath: filein)
                in_doc.initSecurityHandler()
                
                // Create a list of pages to import from one PDF document to another.
                let import_pages: PTVectorPage = PTVectorPage()
                let itr: PTPageIterator = in_doc.getPageIterator(1)
                while itr.hasNext() {
                    import_pages.add(itr.current())
                    itr.next()
                }
                
                let new_doc: PTPDFDoc = PTPDFDoc()
                let imported_pages: PTVectorPage = new_doc.importPages(import_pages, import_bookmarks: false)
                
                // Paper dimension for A3 format in points. Because one inch has
                // 72 points, 11.69 inch 72 = 841.69 points
                let media_box: PTPDFRect = PTPDFRect(x1: 0, y1: 0, x2: 1190.88, y2: 841.69)
                let mid_point: Double = media_box.width() / 2
                
                let builder: PTElementBuilder = PTElementBuilder()
                let writer: PTElementWriter = PTElementWriter()
                
                var i: Int32 = 0
                while i < imported_pages.size() {
                    // Create a blank new A3 page and place on it two pages from the input document.
                    let new_page: PTPage = new_doc.pageCreate(media_box)
                    
                    writer.writerBegin(with: new_page, placement: e_ptoverlay, page_coord_sys: true, compress: true, resources: nil)
                
                    // Place the first page
                    var src_page: PTPage = imported_pages.get(i)
                    var element: PTElement = builder.createForm(with: src_page)
                    
                    var sc_x: Double = mid_point / src_page.getWidth(e_ptcrop)
                    var sc_y: Double = media_box.height() / src_page.getHeight(e_ptcrop)
                    var scale: Double = sc_x < sc_y ? sc_x : sc_y // min(sc_x, sc_y)
                    element.getGState().setTransform(scale, b: 0, c: 0, d: scale, h: 0, v: 0)
                    writer.writePlacedElement(element)
                    
                    // Place the second page
                    i += 1
                    if i < imported_pages.size() {
                        src_page = imported_pages.get(i)
                        element = builder.createForm(with: src_page)
                        sc_x = mid_point / src_page.getWidth(e_ptcrop)
                        sc_y = media_box.height() / src_page.getHeight(e_ptcrop)
                        scale = sc_x < sc_y ? sc_x : sc_y
                        // min(sc_x, sc_y)
                        element.getGState().setTransform(scale, b: 0, c: 0, d: scale, h: mid_point, v: 0)
                        writer.writePlacedElement(element)
                    }
                    
                    writer.end()
                    new_doc.pagePushBack(new_page)
                    i += 1
                }
                
                new_doc.save(toFile: fileout, flags: e_ptlinearized.rawValue)
                print("Done. Result saved in newsletter_booklet.pdf...")
            }
        } catch let e as NSError {
            print("\(e)")
            ret = 1
        }
        
        print("Done.")
        return ret
    }
}
```

{% 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/ios/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.
