class Thinreports::Generator::PDF::Document

Attributes

pdf[R]

@return [Prawn::Document]

Public Class Methods

new(title: nil, security: nil) click to toggle source

@param [String] title (nil) @param [Hash] security (nil)

# File lib/thinreports/generator/pdf/document.rb, line 28
def initialize(title: nil, security: nil)
  @pdf = Prawn::Document.new(
    skip_page_creation: true,
    margin: [0, 0],
    info: {
      CreationDate: Time.now,
      Creator: 'Thinreports Generator for Ruby ' + Thinreports::VERSION,
      Title: title
    }
  )
  # Setup to Prawn::Document.
  setup_fonts
  setup_custom_graphic_states

  # Encrypts the document.
  @pdf.encrypt_document(security) if security
end

Public Instance Methods

create_stamp(id, &block) click to toggle source

Delegate to Prawn::Document#create_stamp @param [String] id @see Prawn::Document#create_stamp

# File lib/thinreports/generator/pdf/document.rb, line 81
def create_stamp(id, &block)
  pdf.create_stamp(id, &block)
end
internal() click to toggle source

@see pdf

# File lib/thinreports/generator/pdf/document.rb, line 86
def internal
  @pdf
end
render() click to toggle source

Delegate to Prawn::Document#render @see Prawn::Document#render

# File lib/thinreports/generator/pdf/document.rb, line 48
def render
  result = pdf.render
  finalize
  result
end
render_file(*args) click to toggle source

Delegate to Prawn::Document#render_file @see Prawn::Document#render_file

# File lib/thinreports/generator/pdf/document.rb, line 56
def render_file(*args)
  finalize
  pdf.render_file(*args)
end
stamp(stamp_id, at = nil) click to toggle source

@param [String] stamp_id @param [Array<Numeric>] at (nil)

# File lib/thinreports/generator/pdf/document.rb, line 70
def stamp(stamp_id, at = nil)
  if at.nil?
    pdf.stamp(stamp_id)
  else
    pdf.stamp_at(stamp_id, rpos(*at))
  end
end
translate(x, y, &block) click to toggle source

@param [Numeric, String] x @param [Numeric, String] y

# File lib/thinreports/generator/pdf/document.rb, line 63
def translate(x, y, &block)
  x, y = rpos(x, y)
  pdf.translate(x, y, &block)
end

Private Instance Methods

finalize() click to toggle source
# File lib/thinreports/generator/pdf/document.rb, line 92
def finalize
  clean_temp_images
end
map_to_upper_left_position(x, y) click to toggle source

@param [Numeric, String] x @param [Numeric, String] y @return [Array<Float>]

# File lib/thinreports/generator/pdf/document.rb, line 122
def map_to_upper_left_position(x, y)
  x, y = s2f(x, y)
  [x, pdf.bounds.height - y]
end
Also aliased as: pos
map_to_upper_left_relative_position(x, y) click to toggle source

@param [Numeric, String] x @param [Numeric, String] y @return [Array<Float>]

# File lib/thinreports/generator/pdf/document.rb, line 113
def map_to_upper_left_relative_position(x, y)
  x, y = s2f(x, y)
  [x, -y]
end
Also aliased as: rpos
pos(x, y)
rpos(x, y)
s2f(*values) click to toggle source

@param [Array<String, Numeric>] values @return [Numeric, Array<Numeric>, nil]

# File lib/thinreports/generator/pdf/document.rb, line 98
def s2f(*values)
  return nil if values.empty?

  if values.size == 1
    value = values.first
    return nil unless value
    value.is_a?(::Numeric) ? value : value.to_f
  else
    values.map { |v| s2f(v) }
  end
end