Some test text!

Search
Hamburger Icon

Change a PDF Page's MediaBox in Ruby

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 Ruby code for using Apryse SDK to change a page's MediaBox using Rect class. Learn more about our Ruby 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-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

	PDFNet.Initialize(PDFTronLicense.Key)
	
	# Relative path to the folder containing the test files.
	input_path = "../../TestFiles/"
	output_path = "../../TestFiles/Output/"
	
	# Test  - Adjust the position of content within the page.
	puts "_______________________________________________"
	puts "Opening the input pdf..."
	
	input_doc = PDFDoc.new(input_path + "tiger.pdf")
	input_doc.InitSecurityHandler
	pg_itr1 = input_doc.GetPageIterator
	
	media_box = Rect.new(pg_itr1.Current.GetMediaBox)
	
	media_box.x1 -= 200	 # translate the page 200 units (1 uint = 1/72 inch)
	media_box.x2 -= 200
	
	media_box.Update
	
	input_doc.Save(output_path + "tiger_shift.pdf", 0)
	input_doc.Close
	PDFNet.Terminate
	puts "Done. Result saved in tiger_shift..."