Optimize PDF File Size in Ruby
Contents
[
Hide
]
Aspose.PDF - Optimize PDF File Size
To optimize file Size of PDF document using Aspose.PDF Java for Ruby, call optimize_filesize method of Optimize module.
Ruby Code
def optimize_filesize()
# The path to the documents directory.
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
# Open a pdf document.
doc = Rjb::import('com.aspose.pdf.Document').new(data_dir + "input1.pdf")
# Optimize the file size by removing unused objects
opt = Rjb::import('aspose.document.OptimizationOptions').new
opt.setRemoveUnusedObjects(true)
opt.setRemoveUnusedStreams(true)
opt.setLinkDuplcateStreams(true)
doc.optimizeResources(opt)
# Save output document
doc.save(data_dir + "Optimized_Filesize.pdf")
puts "Optimized PDF Filesize, please check output file."
end
Download Running Code
Download Optimize PDF File Size (Aspose.PDF) from any of the below mentioned social coding sites: