تحسين حجم ملف PDF في Ruby

Aspose.PDF - تحسين حجم ملف PDF

لتحسين حجم ملف PDF باستخدام Aspose.PDF Java for Ruby، استدعِ طريقة optimize_filesize من الوحدة Optimize.

كود Ruby

 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В

تنزيل التعليمات البرمجية قيد التشغيل

تنزيل Optimize PDF File Size (Aspose.PDF) من أي من المواقع الاجتماعية للبرمجة المذكورة أدناه: