Some test text!

< Mac samples

Change a PDF Page's MediaBox in Ruby

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

Step 1: Get your free trial license key, or sign in

Start Trial
Sign in

Step 2: Add the code:

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

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

$stdout.sync = true

	# 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 = + "tiger.pdf")
	pg_itr1 = input_doc.GetPageIterator
	media_box =
	media_box.x1 -= 200	 # translate the page 200 units (1 uint = 1/72 inch)
	media_box.x2 -= 200
	input_doc.Save(output_path + "tiger_shift.pdf", 0)
	puts "Done. Result saved in tiger_shift..."