WSS_PdfPagesAsChildPdfItems.rb
# Splits a source item (which is a PDF) into a series of PDFs, 1 per
# page in the source PDF.
Splits a source item (which is a PDF) into a series of PDFs, 1 per
page in the source PDF.
Splits a source item ( which is a PDF ) into a series of PDFs 1 per page in the source PDF .
def split_pdf_source_item(source_item,export_directory)
	generated_files = []
	java.io.File.new(export_directory).mkdirs
	input_stream = source_item.getBinary.getBinaryData.getInputStream
	reader = PdfReader.new(input_stream)
	base_name = File.basename(source_item.getLocalisedName,".pdf")
	pages = reader.getNumberOfPages
	pages.times do |page_number|
		page_number += 1
		output_file = File.join(export_directory,"#{base_name}_Page#{page_number.to_s.rjust(4,"0")}.pdf")
		document = Document.new(reader.getPageSizeWithRotation(page_number))
		writer = PdfCopy.new(document,FileOutputStream.new(output_file))
		document.open
		page = writer.getImportedPage(reader,page_number)
		writer.addPage(page)
		document.close
		writer.close
		generated_files << output_file
	end
	reader.close
	return generated_files
end
def split_pdf_source_item ( source_item , export_directory ) generated_files = [ ] java . io . File . new ( export_directory ) . mkdirs input_stream = source_item . getBinary . getBinaryData . getInputStream reader = PdfReader . new ( input_stream ) base_name = File . basename ( source_item . getLocalisedName , ".pdf" ) pages = reader . getNumberOfPages pages . times do | page_number | page_number += 1 output_file = File . join ( export_directory , "#{base_name}_Page#{page_number.to_s.rjust(4,"0")}.pdf" ) document = Document . new ( reader . getPageSizeWithRotation ( page_number ) ) writer = PdfCopy . new ( document , FileOutputStream . new ( output_file ) ) document . open page = writer . getImportedPage ( reader , page_number ) writer . addPage ( page ) document . close writer . close generated_files << output_file end reader . close return generated_files end
Splits a source item (which is a PDF) into a series of PDFs, 1 per
page in the source PDF.
Splits a source item ( which is a PDF ) into a series of PDFs 1 per page in the source PDF .
source_item
export_directory