class HexaPDF::CLI::Modify

Modifies a PDF file:

See: HexaPDF::Task::Optimize

Private Instance Methods

arrange_pages(doc) click to toggle source

Arranges the pages of the document as specified with the –pages option.

# File lib/hexapdf/cli/modify.rb, line 93
def arrange_pages(doc)
  all_pages = doc.pages.to_a
  new_page_tree = doc.add({Type: :Pages})
  parse_pages_specification(@pages, all_pages.length).each do |index, rotation|
    page = all_pages[index]
    page.value.update(page.copy_inherited_values)
    if rotation == :none
      page.delete(:Rotate)
    elsif rotation.kind_of?(Integer)
      page.rotate(rotation)
    end
    new_page_tree.add_page(page)
  end
  doc.catalog[:Pages] = new_page_tree
  remove_unused_pages(doc)
  doc.pages.add unless doc.pages.count > 0
end