Class: Pdfrb::Document::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/document/display.rb

Overview

Catalog display controls. Sets viewer behavior: hide toolbar, page layout, page mode, and open-action destination.

/ViewerPreferences — fine-grained viewer controls /PageLayout — how pages are laid out in the viewer /PageMode — which panels are visible on open /OpenAction — initial destination or action

Constant Summary collapse

PAGE_LAYOUTS =
%i[
  SinglePage OneColumn TwoColumnLeft TwoColumnRight
  TwoPageLeft TwoPageRight
].freeze
PAGE_MODES =
%i[
  UseNone UseOutlines UseThumbs FullScreen UseOC UseAttachments
].freeze
NON_FULLSCREEN_PAGE_MODES =
%i[UseNone UseOutlines UseThumbs UseOC].freeze
DIRECTIONS =
%i[L2R R2L].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Display

Returns a new instance of Display.



28
29
30
# File 'lib/pdfrb/document/display.rb', line 28

def initialize(document)
  @document = document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



26
27
28
# File 'lib/pdfrb/document/display.rb', line 26

def document
  @document
end

Instance Method Details

#open_action=(dest_or_action) ⇒ Object

Set the /OpenAction destination or action.

Parameters:



49
50
51
# File 'lib/pdfrb/document/display.rb', line 49

def open_action=(dest_or_action)
  document.catalog.value[:OpenAction] = dest_or_action
end

#page_layout=(layout) ⇒ Object

Parameters:

  • layout (Symbol)

    one of PAGE_LAYOUTS.

Raises:

  • (ArgumentError)


33
34
35
36
37
# File 'lib/pdfrb/document/display.rb', line 33

def page_layout=(layout)
  raise ArgumentError, "invalid page layout: #{layout}" unless PAGE_LAYOUTS.include?(layout)

  document.catalog.value[:PageLayout] = layout
end

#page_mode=(mode) ⇒ Object

Parameters:

  • mode (Symbol)

    one of PAGE_MODES.

Raises:

  • (ArgumentError)


40
41
42
43
44
# File 'lib/pdfrb/document/display.rb', line 40

def page_mode=(mode)
  raise ArgumentError, "invalid page mode: #{mode}" unless PAGE_MODES.include?(mode)

  document.catalog.value[:PageMode] = mode
end

#presentation_mode!Object

Convenience: hide toolbar and menubar, fit window.



66
67
68
69
70
71
72
73
74
75
# File 'lib/pdfrb/document/display.rb', line 66

def presentation_mode!
  viewer_preferences(
    HideToolbar: true,
    HideMenubar: true,
    FitWindow: true,
    CenterWindow: true,
    DisplayDocTitle: true
  )
  self.page_mode = :FullScreen
end

#viewer_preferences(**opts) ⇒ Object

Get or set /ViewerPreferences as a keyword-hash.



54
55
56
57
58
59
60
61
62
63
# File 'lib/pdfrb/document/display.rb', line 54

def viewer_preferences(**opts)
  return read_viewer_preferences if opts.empty?

  vp = document.catalog.value[:ViewerPreferences]
  vp ||= {}
  opts.each do |key, value|
    vp[key] = value
  end
  document.catalog.value[:ViewerPreferences] = vp
end