Class: PDFBeads::PDFBuilder::PDFTOC

Inherits:
Array
  • Object
show all
Defined in:
lib/pdfbeads/pdftoc.rb

Overview

Read table of contents from an UTF-8 text file and prepare it for placing into a PDF document. The syntax of the TOC file is simple. Each line describes a single outline item according to the following pattern:

<indent>“Title” “Page Number” [0|-|1|+]

The indent is used to determine the level of this outline item: it may consist either of spaces or of tabs, but it is not allowed to mix both characters in the same file. The title and page number are separated with an arbitrary number of whitespace characters and are normally enclosed into double quotes. The third, optional argument specifies if this TOC item should be displayed unfolded by default (i. e. if its descendants should be visible).

The reference to a TOC file can be passed to pdfbeads via the -C (or –toc) option. It is recommended to use this option in combination with the -L (or –labels) parameter, which allows to specify an alternate page numbering for a PDF file: thus your TOC file may contain the same page numbers, as the original book, so that there is no need to care about any numbering offsets.

Defined Under Namespace

Classes: PDFTOCItem

Instance Method Summary collapse

Constructor Details

#initialize(fpath) ⇒ PDFTOC

Returns a new instance of PDFTOC.



79
80
81
82
83
84
85
86
87
# File 'lib/pdfbeads/pdftoc.rb', line 79

def initialize( fpath )
  root = PDFTOCItem[
    :indent   => -1,
    :open     => true,
    :children => Array.new()
  ]
  push( root )
  parseTOC( fpath,root )
end