Method: CombinePDF::PDF#pages

Defined in:
lib/combine_pdf/pdf_public.rb

#pages(catalogs = nil) ⇒ Object

this method returns all the pages cataloged in the catalog.

if no catalog is passed, it seeks the existing catalog(s) and searches for any registered Page objects.

Page objects are Hash class objects. the page methods are added using a mixin or inheritance.

catalogs

a catalog, or an Array of catalog objects. defaults to the existing catalog.



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/combine_pdf/pdf_public.rb', line 221

def pages(catalogs = nil)
  page_list = []
  catalogs ||= get_existing_catalogs

  if catalogs.is_a?(Array)
    catalogs.each { |c| page_list.concat pages(c) unless c.nil? }
  elsif catalogs.is_a?(Hash)
    if catalogs[:is_reference_only]
      if catalogs[:referenced_object]
        page_list.concat pages(catalogs[:referenced_object])
      else
        warn "couldn't follow reference!!! #{catalogs} not found!"
      end
    else
      case catalogs[:Type]
      when :Page
        page_list << catalogs
      when :Pages
        page_list.concat pages(catalogs[:Kids]) unless catalogs[:Kids].nil?
      when :Catalog
        page_list.concat pages(catalogs[:Pages]) unless catalogs[:Pages].nil?
      end
    end
  end
  page_list
end