class Selenium::WebDriver::PrintOptions

Represents options for printing a page.

def initialize

def initialize
  @orientation = DEFAULT_ORIENTATION
  @scale = DEFAULT_SCALE
  @background = false
  @page_ranges = nil
  @page_size = DEFAULT_PAGE_SIZE
  @margins = DEFAULT_MARGINS
end

def page_size=(value)

Parameters:
  • value (Symbol, Hash) -- The predefined size (:letter, :legal, :a4, :tabloid) or a custom hash.
def page_size=(value)
  predefined_sizes = {
    letter: {width: 21.59, height: 27.94},
    legal: {width: 21.59, height: 35.56},
    a4: {width: 21.0, height: 29.7},
    tabloid: {width: 27.94, height: 43.18}
  }
  case value
  when Symbol
    raise ArgumentError, "Invalid page size: #{value}" unless predefined_sizes.key?(value)
    @page_size = predefined_sizes[value]
  when Hash
    unless value.key?(:width) && value.key?(:height)
      raise ArgumentError, 'Custom page size must include :width and :height'
    end
    @page_size = value
  else
    raise ArgumentError, 'Page size must be a Symbol or a Hash'
  end
end

def to_h

Returns:
  • (Hash) -
def to_h
  options = {
    orientation: @orientation,
    scale: @scale,
    background: @background,
    pageRanges: @page_ranges,
    paperWidth: @page_size[:width],
    paperHeight: @page_size[:height],
    marginTop: @margins[:top],
    marginBottom: @margins[:bottom],
    marginLeft: @margins[:left],
    marginRight: @margins[:right]
  }
  options.compact
end