Delete a Particular Page from the PDF File in Ruby

Aspose.PDF - Delete Page

To delete a Particular Page from the PDF document using Aspose.PDF Java for Ruby, simply invoke DeletePage module.

Ruby Code

# The path to the documents directory.

data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'

# Open the target document

pdf = Rjb::import('com.aspose.pdf.Document').new(data_dir + 'input1.pdf')

# delete a particular page

pdf.getPages().delete(2)

# save the newly generated PDF file

pdf.save(data_dir + "output.pdf")

puts "Page deleted successfully!"

Download Running Code

Download Delete Page (Aspose.PDF) from any of the below mentioned social coding sites: