class HexaPDF::Document::Pages

Parent
Included Modules

This class provides methods for managing the pages of a PDF file.

It uses the methods of HexaPDF::Type::PageTreeNode underneath but provides a more convenient interface.

Public Class Methods

new(document)

Creates a new Pages object for the given PDF document.

Public Instance Methods

pages << page → pages

Appends the given page at the end and returns the pages object itself to allow chaining.

[](index)

Returns the page for the zero-based index, or nil if no such page exists.

Negative indices count backwards from the end, i.e. -1 is the last page.

add → new_page
add(media_box, orientation: :portrait) → new_page
add(page) → page

Adds the page or a new empty page at the end and returns it.

If no argument is given, a new page with the default dimensions (see configuration option 'page.default_media_box') is used.

If the single argument is an array with four numbers (specifying the media box), the new page will have these dimensions.

If the single argument is a symbol, it is taken as referencing a pre-defined media box in HexaPDF::Type::Page::PAPER_SIZE for the new page. The optional argument orientation can be used to change the orientation to :landscape if needed.

count()

Returns the number of pages in the PDF document. May be zero if the document has no pages.

Also aliased as: size, length
delete(page)

Deletes the given page object from the document's page tree and the document.

Also see: HexaPDF::Type::PageTreeNode#delete_page

delete_at(index)

Deletes the page object at the given index from the document's page tree and the document.

Also see: HexaPDF::Type::PageTreeNode#delete_page

each {|page| block } → pages
each → Enumerator

Iterates over all pages inorder.

insert(index, page = nil)

Inserts the page or a new empty page at the zero-based index and returns it.

Negative indices count backwards from the end, i.e. -1 is the last page. When using negative indices, the page will be inserted after that element. So using an index of -1 will insert the page after the last page.

length()
Alias for: count
root()

Returns the root of the page tree, a HexaPDF::Type::PageTreeNode object.

size()
Alias for: count