Class: Redmine::Export::PDF::ITCPDF

Inherits:
RBPDF
  • Object
show all
Includes:
I18n
Defined in:
lib/redmine/export/pdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #languages_options, #ll, #month_name, #set_language_if_valid, #valid_languages

Constructor Details

#initialize(lang, orientation = 'P') ⇒ ITCPDF

Returns a new instance of ITCPDF.


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/redmine/export/pdf.rb', line 33

def initialize(lang, orientation='P')
  @@k_path_cache = Rails.root.join('tmp', 'pdf')
  FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
  set_language_if_valid lang
  super(orientation, 'mm', 'A4')
  set_print_header(false)
  set_rtl(l(:direction) == 'rtl')
  set_temp_rtl(l(:direction) == 'rtl' ? 'R' : 'L')

  @font_for_content = l(:general_pdf_fontname)
  @font_for_footer  = l(:general_pdf_fontname)
  set_creator(Redmine::Info.app_name)
  set_font(@font_for_content)

  set_header_font([@font_for_content, '', 10])
  set_footer_font([@font_for_content, '', 8])
  set_default_monospaced_font(@font_for_content)
end

Instance Attribute Details

Returns the value of attribute footer_date


31
32
33
# File 'lib/redmine/export/pdf.rb', line 31

def footer_date
  @footer_date
end

Instance Method Details

#fix_text_encoding(txt) ⇒ Object


57
58
59
# File 'lib/redmine/export/pdf.rb', line 57

def fix_text_encoding(txt)
  RDMPdfEncoding::rdm_from_utf8(txt, "UTF-8")
end

111
112
113
114
115
116
117
118
119
120
121
# File 'lib/redmine/export/pdf.rb', line 111

def Footer
  set_font(@font_for_footer, 'I', 8)
  set_x(15)
  if get_rtl
    RDMCell(0, 5, @footer_date, 0, 0, 'R')
  else
    RDMCell(0, 5, @footer_date, 0, 0, 'L')
  end
  set_x(-30)
  RDMCell(0, 5, get_alias_num_page() + '/' + get_alias_nb_pages(), 0, 0, 'C')
end

#formatted_text(text) ⇒ Object


61
62
63
64
65
66
# File 'lib/redmine/export/pdf.rb', line 61

def formatted_text(text)
  html = Redmine::WikiFormatting.to_html(Setting.text_formatting, text)
  # Strip {{toc}} tags
  html.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i, '')
  html
end

#get_image_filename(attrname) ⇒ Object


94
95
96
97
98
99
100
101
# File 'lib/redmine/export/pdf.rb', line 94

def get_image_filename(attrname)
  atta = RDMPdfEncoding.attach(@attachments, attrname, "UTF-8")
  if atta
    return atta.diskfile
  else
    return nil
  end
end

#get_sever_url(url) ⇒ Object


103
104
105
106
107
108
109
# File 'lib/redmine/export/pdf.rb', line 103

def get_sever_url(url)
  if !empty_string(url) and (url[0, 1] == '/')
    Setting.host_name.split('/')[0] + url
  else
    url
  end
end

#RDMCell(w, h = 0, txt = '', border = 0, ln = 0, align = '', fill = 0, link = '') ⇒ Object


68
69
70
# File 'lib/redmine/export/pdf.rb', line 68

def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
  cell(w, h, txt, border, ln, align, fill, link)
end

#RDMMultiCell(w, h = 0, txt = '', border = 0, align = '', fill = 0, ln = 1) ⇒ Object


72
73
74
# File 'lib/redmine/export/pdf.rb', line 72

def RDMMultiCell(w, h=0, txt='', border=0, align='', fill=0, ln=1)
  multi_cell(w, h, txt, border, align, fill, ln)
end

#RDMwriteHTMLCell(w, h, x, y, txt = '', attachments = [], border = 0, ln = 1, fill = 0) ⇒ Object


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/redmine/export/pdf.rb', line 76

def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
  @attachments = attachments

  css_tag = ' <style>
  table, td {
    border: 2px #ff0000 solid;
  }
  th {  background-color:#EEEEEE; padding: 4px; white-space:nowrap; text-align: center;  font-style: bold;}
  pre {
    background-color: #fafafa;
  }
  </style>'

  writeHTMLCell(w, h, x, y,
    css_tag + formatted_text(txt),
    border, ln, fill)
end

#SetFontStyle(style, size) ⇒ Object


52
53
54
55
# File 'lib/redmine/export/pdf.rb', line 52

def SetFontStyle(style, size)
  style.delete!('B') if current_language.to_s.downcase == 'th' # FreeSerif Bold Thai font has problem.
  set_font(@font_for_content, style, size)
end