Some test text!

Search
Hamburger Icon

Change a PDF Page's MediaBox in Go

More languages

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

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

Get Started Samples Download

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

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

package main
import (
	"fmt"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

func main(){
	PDFNetInitialize(PDFTronLicense.Key)
	// Relative path to the folder containing test files.
	var inputPath = "../../TestFiles/"
	var outputPath = "../../TestFiles/Output/"
    // Test  - Adjust the position of content within the page.
    fmt.Println("_______________________________________________")
    fmt.Println("Opening the input pdf...")
    
    inputDoc := NewPDFDoc(inputPath + "tiger.pdf")
    inputDoc.InitSecurityHandler()
    pgItr1 := inputDoc.GetPageIterator()
    
    mediaBox := NewRect(pgItr1.Current().GetMediaBox())
    
    mediaBox.SetX1(mediaBox.GetX1() - 200)     // translate the page 200 units (1 uint = 1/72 inch)
    mediaBox.SetX2(mediaBox.GetX2() - 200)    
    
    mediaBox.Update()
    
    inputDoc.Save(outputPath + "tiger_shift.pdf", uint(0))
    inputDoc.Close()
    
    PDFNetTerminate()
    fmt.Println("Done. Result saved in tiger_shift...")    
}