Some test text!


Change a PDF Page's MediaBox in Swift

Sample Swift code for using PDFTron SDK to change a page's MediaBox using Rect class. Learn more about our PDF Editing & Manipulation Library.

Get StartedSamplesDownload

To run this sample, get started with a free trial of PDFTron SDK.

// Copyright (c) 2001-2019 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("Opening the input pdf...")
                let input_doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "tiger", ofType: "pdf"))
                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)
       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

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn More