Rect

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

1//
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3//
4
5using System;
6using pdftron;
7using pdftron.Common;
8using pdftron.Filters;
9using pdftron.SDF;
10using pdftron.PDF;
11
12namespace RectTestCS
13{
14 /// <summary>
15 /// Summary description for Class1.
16 /// </summary>
17 class Class1
18 {
19 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
20 static Class1() {}
21
22 /// <summary>
23 /// The main entry point for the application.
24 /// </summary>
25 [STAThread]
26 static void Main(string[] args)
27 {
28 PDFNet.Initialize(PDFTronLicense.Key);
29 // Relative path to the folder containing test files.
30 string input_path = "../../../../TestFiles/";
31 string output_path = "../../../../TestFiles/Output/";
32
33 Console.WriteLine("_______________________________________________");
34 Console.WriteLine("Opening the input pdf...");
35
36 try // Test - Adjust the position of content within the page.
37 {
38 using (PDFDoc input_doc = new PDFDoc(input_path + "tiger.pdf"))
39 {
40 input_doc.InitSecurityHandler();
41
42 Page pg = input_doc.GetPage(1);
43 Rect media_box = pg.GetMediaBox();
44
45 media_box.x1 -= 200; // translate the page 200 units (1 uint = 1/72 inch)
46 media_box.x2 -= 200;
47
48 media_box.Update();
49
50 input_doc.Save(output_path + "tiger_shift.pdf", 0);
51 }
52
53 Console.WriteLine("Done. Result saved in tiger_shift...");
54 }
55 catch (PDFNetException e)
56 {
57 Console.WriteLine(e.Message);
58 }
59 PDFNet.Terminate();
60 }
61 }
62}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales