Class: Thinreports::BasicReport::Generator::PDF::Document

Inherits:
Object
  • Object
show all
Includes:
DrawShape, DrawTemplateItems, Font, Graphics, Page, ParseColor, Utils
Defined in:
lib/thinreports/basic_report/generator/pdf/document.rb

Constant Summary

Constants included from Page

Page::JIS_SIZES

Constants included from Graphics

Graphics::BASE_LINE_WIDTH, Graphics::STROKE_DASH

Constants included from Font

Font::BUILTIN_FONTS, Font::DEFAULT_FALLBACK_FONTS, Font::FONT_STORE, Font::PRAWN_BUINTIN_FONT_ALIASES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Page

#add_blank_page, #max_content_height, #start_new_page, #start_new_page_for_section_report

Methods included from DrawTemplateItems

#draw_template_items

Methods included from DrawShape

#draw_shape_ellipse, #draw_shape_iblock, #draw_shape_image, #draw_shape_line, #draw_shape_pageno, #draw_shape_rect, #draw_shape_tblock, #draw_shape_text, #shape_iblock_dimenions

Methods included from Graphics

#base64image, #build_fill_styles, #build_graphic_attributes, #build_stroke_styles, #build_text_attributes, #clean_temp_images, #create_temp_imagefile, #ellipse, #font_family, #font_styles, #image, #image_box, #image_dimensions, #image_position_x, #image_position_y, #letter_spacing, #line, #line_height, #migrate_overflow_wrap_from_word_wrap, #overflow_wrap, #rect, #temp_image_registry, #text, #text_align, #text_box, #text_overflow, #text_valign, #with_graphic_styles, #word_wrap

Methods included from ParseColor

#parse_color

Methods included from Font

#default_family, #default_family_if_missing, #font_has_style?, #install_font, #setup_fonts

Methods included from Utils

#blank_value?, #call_block_in, #deep_copy, included

Constructor Details

#initialize(title: nil, security: nil) ⇒ Document

Returns a new instance of Document.

Parameters:

  • title (String) (defaults to: nil)

    (nil)

  • security (Hash) (defaults to: nil)

    (nil)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 29

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

Instance Attribute Details

#pdfPrawn::Document (readonly)

Returns:

  • (Prawn::Document)


25
26
27
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 25

def pdf
  @pdf
end

Instance Method Details

#create_stamp(id, &block) ⇒ Object

Delegate to Prawn::Document#create_stamp

Parameters:

  • id (String)

See Also:

  • Prawn::Document#create_stamp


82
83
84
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 82

def create_stamp(id, &block)
  pdf.create_stamp(id, &block)
end

#internalObject

See Also:



87
88
89
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 87

def internal
  @pdf
end

#renderObject

Delegate to Prawn::Document#render

See Also:

  • Prawn::Document#render


49
50
51
52
53
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 49

def render
  result = pdf.render
  finalize
  result
end

#render_file(*args) ⇒ Object

Delegate to Prawn::Document#render_file

See Also:

  • Prawn::Document#render_file


57
58
59
60
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 57

def render_file(*args)
  finalize
  pdf.render_file(*args)
end

#stamp(stamp_id, at = nil) ⇒ Object

Parameters:

  • stamp_id (String)
  • at (Array<Numeric>) (defaults to: nil)

    (nil)



71
72
73
74
75
76
77
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 71

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) ⇒ Object

Parameters:

  • x (Numeric, String)
  • y (Numeric, String)


64
65
66
67
# File 'lib/thinreports/basic_report/generator/pdf/document.rb', line 64

def translate(x, y, &block)
  x, y = rpos(x, y)
  pdf.translate(x, y, &block)
end