Sample Obj-C code for using Apryse SDK to change a page's MediaBox using Rect class. Learn more about our iOS SDK and PDF Editing & Manipulation Library.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#import <OBJC/PDFNetOBJC.h>
7#import <Foundation/Foundation.h>
8
9int main(int argc, char *argv[])
10{
11 @autoreleasepool {
12 int ret = 0;
13 [PTPDFNet Initialize: 0];
14
15 @try // Test - Adjust the position of content within the page.
16 {
17 NSLog(@"_______________________________________________");
18 NSLog(@"Opening the input pdf...");
19
20 PTPDFDoc *input_doc = [[PTPDFDoc alloc] initWithFilepath: @"../../TestFiles/tiger.pdf"];
21 [input_doc InitSecurityHandler];
22
23 PTPageIterator *pg_itr1 = [input_doc GetPageIterator: 1];
24
25 PTPDFRect * media_box = [[pg_itr1 Current] GetMediaBox];
26
27 [media_box SetX1: [media_box GetX1] - 200]; // translate the page 200 units (1 uint = 1/72 inch)
28 [media_box SetX2: [media_box GetX2] - 200];
29
30 [media_box Update: [[PTObj alloc] init]];
31
32 [input_doc SaveToFile: @"../../TestFiles/Output/tiger_shift.pdf" flags: 0];
33
34 NSLog(@"Done. Result saved in tiger_shift...");
35 }
36 @catch(NSException *e)
37 {
38 NSLog(@"Caught PDFNet exception: %@", e.reason);
39 ret = 1;
40 }
41 [PTPDFNet Terminate: 0];
42 return ret;
43 }
44}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import PDFNet
7import Foundation
8
9func runRectTest() -> Int {
10 return autoreleasepool {
11 var ret: Int = 0
12
13
14 do {
15 try PTPDFNet.catchException {
16 // Test - Adjust the position of content within the page.
17 print("_______________________________________________")
18 print("Opening the input pdf...")
19
20 let input_doc: PTPDFDoc = PTPDFDoc(filepath: Bundle.main.path(forResource: "tiger", ofType: "pdf"))
21 input_doc.initSecurityHandler()
22
23 let pg_itr1: PTPageIterator = input_doc.getPageIterator(1)
24
25 let media_box: PTPDFRect = pg_itr1.current().getMediaBox()
26
27 media_box.setX1(media_box.getX1() - 200) // translate the page 200 units (1 uint = 1/72 inch)
28 media_box.setX2(media_box.getX2() - 200)
29
30 media_box.update(PTObj())
31
32 input_doc.save(toFile: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("tiger_shift.pdf").path, flags: 0)
33
34 print("Done. Result saved in tiger_shift...")
35 }
36 } catch let e as NSError {
37 print("Caught PDFNet exception: \(e)")
38 ret = 1
39 }
40
41 return ret
42 }
43}
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales