Sample C# code for using Apryse SDK to change a page's MediaBox using Rect class. Learn more about our UWP SDK and PDF Editing & Manipulation Library.
1//
2// Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
3//
4
5using System;
6using System.IO;
7using System.Threading.Tasks;
8using Windows.Foundation;
9
10using pdftron.PDF;
11
12using PDFNetUniversalSamples.ViewModels;
13
14namespace PDFNetSamples
15{
16 public sealed class RectTest : Sample
17 {
18 public RectTest() :
19 base("Rect", "Shows how to change Page's MediaBox using Rect class.")
20 {
21 }
22
23 public override IAsyncAction RunAsync()
24 {
25 return Task.Run(new System.Action(async () => {
26 WriteLine("--------------------------------");
27 WriteLine("Starting Rect Test...");
28 WriteLine("--------------------------------\n");
29
30 string input_file_path = Path.Combine(InputPath, "tiger.pdf");
31 WriteLine("Opening input file " + input_file_path);
32
33 try // Test - Adjust the position of content within the page.
34 {
35 PDFDoc input_doc = new PDFDoc(input_file_path);
36 input_doc.InitSecurityHandler();
37
38 pdftron.PDF.Page pg = input_doc.GetPage(1);
39 pdftron.PDF.Rect media_box = pg.GetMediaBox();
40
41 media_box.x1 -= 200; // translate the page 200 units (1 UInt = 1/72 inch)
42 media_box.x2 -= 200;
43
44 media_box.Update();
45
46 String output_file_path = Path.Combine(OutputPath, "tiger_shift.pdf");
47 await input_doc.SaveAsync(output_file_path, 0);
48 input_doc.Destroy();
49
50 WriteLine("Done. Results saved in " + output_file_path);
51 await AddFileToOutputList(output_file_path).ConfigureAwait(false);
52 }
53 catch (Exception e)
54 {
55 WriteLine(GetExceptionMessage(e));
56 }
57
58 WriteLine("\n--------------------------------");
59 WriteLine("Done Rect Test.");
60 WriteLine("--------------------------------\n");
61 })).AsAsyncAction();
62 }
63 }
64}
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales