Some test text!

menu

Change a PDF Page's MediaBox in Obj-C

More languages

chevron_right
More languages
JavaScript
Java (Android)
C++
C#
C# (.NET Core)
Java
Kotlin
Obj-C
JS (Node.js)
PHP
Python
Ruby
Swift
C# (UWP)
VB
C# (Xamarin)

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

Get StartedSamplesDownload

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

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

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

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

        @try // Test  - Adjust the position of content within the page.
        {
            NSLog(@"_______________________________________________");
            NSLog(@"Opening the input pdf...");

            PTPDFDoc *input_doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/tiger.pdf"];
            [input_doc InitSecurityHandler];

            PTPageIterator *pg_itr1 = [input_doc GetPageIterator: 1];

            PTPDFRect * media_box = [[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 alloc] init]];		
        
            [input_doc SaveToFile: @"../../TestFiles/Output/tiger_shift.pdf" flags: 0];

            NSLog(@"Done. Result saved in tiger_shift...");
        }
        @catch(NSException *e)
        {
            NSLog(@"Caught PDFNet exception: %@", e.reason);
            ret = 1;
        }
        
        return ret;
    }
}
close

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.

Upcoming webinar: How to add document collaboration to your app

Learn More
close