< iOS samples

RectTest - Swift

Shows how to change Page's MediaBox using Rect class.

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

import PDFNet
import Foundation

func runRectTest() -> Int {
    return autoreleasepool {
        var ret: Int = 0
        
        
        do {
            try PTPDFNet.catchException {
                // Test  - Adjust the position of content within the page.
                print("_______________________________________________")
                print("Opening the input pdf...")
                
                let input_doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "tiger", ofType: "pdf"))
                input_doc.initSecurityHandler()
                
                let pg_itr1: PTPageIterator = input_doc.getPageIterator(1)
                
                let media_box: PTPDFRect = pg_itr1.current().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(PTObj())
                
                input_doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("tiger_shift.pdf").path, flags: 0)
                
                print("Done. Result saved in tiger_shift...")
            }
        } catch let e as NSError {
            print("Caught PDFNet exception: \(e)")
            ret = 1
        }
        
        return ret
    }
}