Split PDF File into Individual Pages in Ruby

Aspose.PDF - Split Pages

To split PDF document into individual pages using Aspose.PDF Java for Ruby, simply invoke SplitAllPages 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')

# loop through all the pages

pdf_page = 1

#for (int pdfPage = 1; pdfPage<= pdfDocument1.getPages().size(); pdfPage++)

while pdf_page <= pdf.getPages().size()

# create a new Document object

new_document = Rjb::import('com.aspose.pdf.Document').new

# get the page at particular index of Page Collection


# save the newly generated PDF file

new_document.save(data_dir + "page_#{pdf_page}.pdf")

pdf_page +=1


puts "Split process completed successfully!"

Download Running Code

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