Change PDF Media Box - Rect - Go Sample Code

Sample code for using Apryse SDK to change a page's MediaBox using Rect class. Sample code provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby and VB.

Learn more about our Server SDK and PDF Editing & Manipulation Library.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult LICENSE.txt regarding license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8 "fmt"
9 . "pdftron"
10)
11
12import "pdftron/Samples/LicenseKey/GO"
13
14func main(){
15 PDFNetInitialize(PDFTronLicense.Key)
16 // Relative path to the folder containing test files.
17 var inputPath = "../../TestFiles/"
18 var outputPath = "../../TestFiles/Output/"
19 // Test - Adjust the position of content within the page.
20 fmt.Println("_______________________________________________")
21 fmt.Println("Opening the input pdf...")
22
23 inputDoc := NewPDFDoc(inputPath + "tiger.pdf")
24 inputDoc.InitSecurityHandler()
25 pgItr1 := inputDoc.GetPageIterator()
26
27 mediaBox := NewRect(pgItr1.Current().GetMediaBox())
28
29 mediaBox.SetX1(mediaBox.GetX1() - 200) // translate the page 200 units (1 uint = 1/72 inch)
30 mediaBox.SetX2(mediaBox.GetX2() - 200)
31
32 mediaBox.Update()
33
34 inputDoc.Save(outputPath + "tiger_shift.pdf", uint(0))
35 inputDoc.Close()
36
37 PDFNetTerminate()
38 fmt.Println("Done. Result saved in tiger_shift...")
39}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales