annotate lib/redmine/export/pdf.rb @ 1469:c77ab1edff6b bug_563

Close obsolete branch bug_563
author Chris Cannam
date Wed, 23 Jan 2013 14:12:47 +0000
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@0 1 # encoding: utf-8
Chris@0 2 #
Chris@0 3 # Redmine - project management software
Chris@441 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 5 #
Chris@0 6 # This program is free software; you can redistribute it and/or
Chris@0 7 # modify it under the terms of the GNU General Public License
Chris@0 8 # as published by the Free Software Foundation; either version 2
Chris@0 9 # of the License, or (at your option) any later version.
Chris@441 10 #
Chris@0 11 # This program is distributed in the hope that it will be useful,
Chris@0 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 14 # GNU General Public License for more details.
Chris@441 15 #
Chris@0 16 # You should have received a copy of the GNU General Public License
Chris@0 17 # along with this program; if not, write to the Free Software
Chris@0 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 19
Chris@0 20 require 'iconv'
Chris@441 21 require 'fpdf/chinese'
Chris@441 22 require 'fpdf/japanese'
Chris@441 23 require 'fpdf/korean'
Chris@909 24 require 'core/rmagick'
Chris@0 25
Chris@0 26 module Redmine
Chris@0 27 module Export
Chris@0 28 module PDF
Chris@0 29 include ActionView::Helpers::TextHelper
Chris@0 30 include ActionView::Helpers::NumberHelper
Chris@909 31 include IssuesHelper
Chris@441 32
Chris@441 33 class ITCPDF < TCPDF
Chris@0 34 include Redmine::I18n
Chris@0 35 attr_accessor :footer_date
Chris@441 36
Chris@0 37 def initialize(lang)
Chris@909 38 @@k_path_cache = Rails.root.join('tmp', 'pdf')
Chris@909 39 FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
Chris@0 40 set_language_if_valid lang
Chris@441 41 pdf_encoding = l(:general_pdf_encoding).upcase
Chris@441 42 super('P', 'mm', 'A4', (pdf_encoding == 'UTF-8'), pdf_encoding)
Chris@507 43 case current_language.to_s.downcase
Chris@507 44 when 'vi'
Chris@507 45 @font_for_content = 'DejaVuSans'
Chris@507 46 @font_for_footer = 'DejaVuSans'
Chris@0 47 else
Chris@507 48 case pdf_encoding
Chris@507 49 when 'UTF-8'
Chris@507 50 @font_for_content = 'FreeSans'
Chris@507 51 @font_for_footer = 'FreeSans'
Chris@507 52 when 'CP949'
Chris@507 53 extend(PDF_Korean)
Chris@507 54 AddUHCFont()
Chris@507 55 @font_for_content = 'UHC'
Chris@507 56 @font_for_footer = 'UHC'
Chris@507 57 when 'CP932', 'SJIS', 'SHIFT_JIS'
Chris@507 58 extend(PDF_Japanese)
Chris@507 59 AddSJISFont()
Chris@507 60 @font_for_content = 'SJIS'
Chris@507 61 @font_for_footer = 'SJIS'
Chris@507 62 when 'GB18030'
Chris@507 63 extend(PDF_Chinese)
Chris@507 64 AddGBFont()
Chris@507 65 @font_for_content = 'GB'
Chris@507 66 @font_for_footer = 'GB'
Chris@507 67 when 'BIG5'
Chris@507 68 extend(PDF_Chinese)
Chris@507 69 AddBig5Font()
Chris@507 70 @font_for_content = 'Big5'
Chris@507 71 @font_for_footer = 'Big5'
Chris@507 72 else
Chris@507 73 @font_for_content = 'Arial'
Chris@507 74 @font_for_footer = 'Helvetica'
Chris@507 75 end
Chris@0 76 end
Chris@0 77 SetCreator(Redmine::Info.app_name)
Chris@0 78 SetFont(@font_for_content)
Chris@0 79 end
Chris@441 80
Chris@0 81 def SetFontStyle(style, size)
Chris@0 82 SetFont(@font_for_content, style, size)
Chris@0 83 end
Chris@441 84
Chris@0 85 def SetTitle(txt)
Chris@0 86 txt = begin
Chris@0 87 utf16txt = Iconv.conv('UTF-16BE', 'UTF-8', txt)
Chris@0 88 hextxt = "<FEFF" # FEFF is BOM
Chris@0 89 hextxt << utf16txt.unpack("C*").map {|x| sprintf("%02X",x) }.join
Chris@0 90 hextxt << ">"
Chris@0 91 rescue
Chris@0 92 txt
Chris@0 93 end || ''
Chris@0 94 super(txt)
Chris@0 95 end
Chris@441 96
Chris@0 97 def textstring(s)
Chris@0 98 # Format a text string
Chris@0 99 if s =~ /^</ # This means the string is hex-dumped.
Chris@0 100 return s
Chris@0 101 else
Chris@0 102 return '('+escape(s)+')'
Chris@0 103 end
Chris@0 104 end
Chris@441 105
Chris@441 106 def fix_text_encoding(txt)
Chris@909 107 RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding))
Chris@0 108 end
Chris@441 109
Chris@507 110 def RDMCell(w ,h=0, txt='', border=0, ln=0, align='', fill=0, link='')
Chris@507 111 Cell(w, h, fix_text_encoding(txt), border, ln, align, fill, link)
Chris@441 112 end
Chris@441 113
Chris@507 114 def RDMMultiCell(w, h=0, txt='', border=0, align='', fill=0, ln=1)
Chris@507 115 MultiCell(w, h, fix_text_encoding(txt), border, align, fill, ln)
Chris@441 116 end
Chris@441 117
Chris@909 118 def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
Chris@909 119 @attachments = attachments
Chris@909 120 writeHTMLCell(w, h, x, y,
Chris@909 121 fix_text_encoding(
Chris@909 122 Redmine::WikiFormatting.to_html(Setting.text_formatting, txt)),
Chris@909 123 border, ln, fill)
Chris@909 124 end
Chris@909 125
Chris@909 126 def getImageFilename(attrname)
Chris@909 127 # attrname: general_pdf_encoding string file/uri name
Chris@909 128 atta = RDMPdfEncoding.attach(@attachments, attrname, l(:general_pdf_encoding))
Chris@909 129 if atta
Chris@909 130 return atta.diskfile
Chris@909 131 else
Chris@909 132 return nil
Chris@909 133 end
Chris@909 134 end
Chris@909 135
Chris@0 136 def Footer
Chris@0 137 SetFont(@font_for_footer, 'I', 8)
Chris@0 138 SetY(-15)
Chris@0 139 SetX(15)
Chris@441 140 RDMCell(0, 5, @footer_date, 0, 0, 'L')
Chris@0 141 SetY(-15)
Chris@0 142 SetX(-30)
Chris@441 143 RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
Chris@0 144 end
Chris@0 145 end
Chris@441 146
Chris@0 147 # Returns a PDF string of a list of issues
Chris@0 148 def issues_to_pdf(issues, project, query)
Chris@441 149 pdf = ITCPDF.new(current_language)
Chris@0 150 title = query.new_record? ? l(:label_issue_plural) : query.name
Chris@0 151 title = "#{project} - #{title}" if project
Chris@0 152 pdf.SetTitle(title)
Chris@441 153 pdf.alias_nb_pages
Chris@0 154 pdf.footer_date = format_date(Date.today)
Chris@441 155 pdf.SetAutoPageBreak(false)
Chris@0 156 pdf.AddPage("L")
Chris@441 157
Chris@441 158 # Landscape A4 = 210 x 297 mm
Chris@441 159 page_height = 210
Chris@441 160 page_width = 297
Chris@441 161 right_margin = 10
Chris@441 162 bottom_margin = 20
Chris@441 163 col_id_width = 10
Chris@441 164 row_height = 5
Chris@441 165
Chris@441 166 # column widths
Chris@441 167 table_width = page_width - right_margin - 10 # fixed left margin
Chris@0 168 col_width = []
Chris@0 169 unless query.columns.empty?
Chris@441 170 col_width = query.columns.collect do |c|
Chris@909 171 (c.name == :subject || (c.is_a?(QueryCustomFieldColumn) &&
Chris@909 172 ['string', 'text'].include?(c.custom_field.field_format))) ? 4.0 : 1.0
Chris@441 173 end
Chris@441 174 ratio = (table_width - col_id_width) / col_width.inject(0) {|s,w| s += w}
Chris@0 175 col_width = col_width.collect {|w| w * ratio}
Chris@0 176 end
Chris@441 177
Chris@0 178 # title
Chris@441 179 pdf.SetFontStyle('B',11)
Chris@441 180 pdf.RDMCell(190,10, title)
Chris@0 181 pdf.Ln
Chris@441 182
Chris@0 183 # headers
Chris@0 184 pdf.SetFontStyle('B',8)
Chris@0 185 pdf.SetFillColor(230, 230, 230)
Chris@441 186
Chris@441 187 # render it background to find the max height used
Chris@441 188 base_x = pdf.GetX
Chris@441 189 base_y = pdf.GetY
Chris@441 190 max_height = issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
Chris@441 191 pdf.Rect(base_x, base_y, table_width, max_height, 'FD');
Chris@441 192 pdf.SetXY(base_x, base_y);
Chris@441 193
Chris@441 194 # write the cells on page
Chris@441 195 pdf.RDMCell(col_id_width, row_height, "#", "T", 0, 'C', 1)
Chris@441 196 issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
Chris@441 197 issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
Chris@441 198 pdf.SetY(base_y + max_height);
Chris@441 199
Chris@0 200 # rows
Chris@0 201 pdf.SetFontStyle('',8)
Chris@0 202 pdf.SetFillColor(255, 255, 255)
Chris@0 203 previous_group = false
Chris@909 204 issue_list(issues) do |issue, level|
Chris@441 205 if query.grouped? &&
Chris@441 206 (group = query.group_by_column.value(issue)) != previous_group
Chris@0 207 pdf.SetFontStyle('B',9)
Chris@441 208 pdf.RDMCell(277, row_height,
chris@22 209 (group.blank? ? 'None' : group.to_s) + " (#{query.issue_count_by_group[group]})",
Chris@0 210 1, 1, 'L')
Chris@0 211 pdf.SetFontStyle('',8)
Chris@0 212 previous_group = group
Chris@0 213 end
Chris@441 214 # fetch all the row values
Chris@441 215 col_values = query.columns.collect do |column|
Chris@0 216 s = if column.is_a?(QueryCustomFieldColumn)
Chris@0 217 cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
Chris@0 218 show_value(cv)
Chris@0 219 else
Chris@0 220 value = issue.send(column.name)
Chris@909 221 if column.name == :subject
Chris@909 222 value = " " * level + value
Chris@909 223 end
Chris@0 224 if value.is_a?(Date)
Chris@0 225 format_date(value)
Chris@0 226 elsif value.is_a?(Time)
Chris@0 227 format_time(value)
Chris@0 228 else
Chris@0 229 value
Chris@0 230 end
Chris@0 231 end
Chris@441 232 s.to_s
Chris@0 233 end
Chris@441 234
Chris@441 235 # render it off-page to find the max height used
Chris@441 236 base_x = pdf.GetX
Chris@441 237 base_y = pdf.GetY
Chris@441 238 pdf.SetY(2 * page_height)
Chris@441 239 max_height = issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
Chris@441 240 pdf.SetXY(base_x, base_y)
Chris@441 241
Chris@441 242 # make new page if it doesn't fit on the current one
Chris@441 243 space_left = page_height - base_y - bottom_margin
Chris@441 244 if max_height > space_left
Chris@441 245 pdf.AddPage("L")
Chris@441 246 base_x = pdf.GetX
Chris@441 247 base_y = pdf.GetY
Chris@441 248 end
Chris@441 249
Chris@441 250 # write the cells on page
Chris@441 251 pdf.RDMCell(col_id_width, row_height, issue.id.to_s, "T", 0, 'C', 1)
Chris@441 252 issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
Chris@441 253 issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
Chris@441 254 pdf.SetY(base_y + max_height);
Chris@0 255 end
Chris@441 256
Chris@0 257 if issues.size == Setting.issues_export_limit.to_i
Chris@0 258 pdf.SetFontStyle('B',10)
Chris@441 259 pdf.RDMCell(0, row_height, '...')
Chris@0 260 end
Chris@0 261 pdf.Output
Chris@0 262 end
chris@22 263
Chris@441 264 # Renders MultiCells and returns the maximum height used
Chris@441 265 def issues_to_pdf_write_cells(pdf, col_values, col_widths,
Chris@441 266 row_height, head=false)
Chris@441 267 base_y = pdf.GetY
Chris@441 268 max_height = row_height
Chris@441 269 col_values.each_with_index do |column, i|
Chris@441 270 col_x = pdf.GetX
Chris@441 271 if head == true
Chris@441 272 pdf.RDMMultiCell(col_widths[i], row_height, column.caption, "T", 'L', 1)
Chris@441 273 else
Chris@441 274 pdf.RDMMultiCell(col_widths[i], row_height, column, "T", 'L', 1)
Chris@441 275 end
Chris@441 276 max_height = (pdf.GetY - base_y) if (pdf.GetY - base_y) > max_height
Chris@441 277 pdf.SetXY(col_x + col_widths[i], base_y);
Chris@441 278 end
Chris@441 279 return max_height
Chris@441 280 end
Chris@441 281
Chris@441 282 # Draw lines to close the row (MultiCell border drawing in not uniform)
Chris@441 283 def issues_to_pdf_draw_borders(pdf, top_x, top_y, lower_y,
Chris@441 284 id_width, col_widths)
Chris@441 285 col_x = top_x + id_width
Chris@441 286 pdf.Line(col_x, top_y, col_x, lower_y) # id right border
Chris@441 287 col_widths.each do |width|
Chris@441 288 col_x += width
Chris@441 289 pdf.Line(col_x, top_y, col_x, lower_y) # columns right border
Chris@441 290 end
Chris@441 291 pdf.Line(top_x, top_y, top_x, lower_y) # left border
Chris@441 292 pdf.Line(top_x, lower_y, col_x, lower_y) # bottom border
Chris@441 293 end
Chris@441 294
Chris@0 295 # Returns a PDF string of a single issue
Chris@0 296 def issue_to_pdf(issue)
Chris@441 297 pdf = ITCPDF.new(current_language)
Chris@0 298 pdf.SetTitle("#{issue.project} - ##{issue.tracker} #{issue.id}")
Chris@441 299 pdf.alias_nb_pages
Chris@0 300 pdf.footer_date = format_date(Date.today)
Chris@0 301 pdf.AddPage
Chris@441 302 pdf.SetFontStyle('B',11)
Chris@909 303 buf = "#{issue.project} - #{issue.tracker} # #{issue.id}"
Chris@909 304 pdf.RDMMultiCell(190, 5, buf)
Chris@909 305 pdf.Ln
Chris@909 306 pdf.SetFontStyle('',8)
Chris@909 307 base_x = pdf.GetX
Chris@909 308 i = 1
Chris@909 309 issue.ancestors.each do |ancestor|
Chris@909 310 pdf.SetX(base_x + i)
Chris@909 311 buf = "#{ancestor.tracker} # #{ancestor.id} (#{ancestor.status.to_s}): #{ancestor.subject}"
Chris@909 312 pdf.RDMMultiCell(190 - i, 5, buf)
Chris@909 313 i += 1 if i < 35
Chris@909 314 end
Chris@0 315 pdf.Ln
Chris@441 316
Chris@0 317 pdf.SetFontStyle('B',9)
Chris@441 318 pdf.RDMCell(35,5, l(:field_status) + ":","LT")
Chris@0 319 pdf.SetFontStyle('',9)
Chris@441 320 pdf.RDMCell(60,5, issue.status.to_s,"RT")
Chris@0 321 pdf.SetFontStyle('B',9)
Chris@441 322 pdf.RDMCell(35,5, l(:field_priority) + ":","LT")
Chris@0 323 pdf.SetFontStyle('',9)
Chris@441 324 pdf.RDMCell(60,5, issue.priority.to_s,"RT")
Chris@0 325 pdf.Ln
Chris@441 326
Chris@0 327 pdf.SetFontStyle('B',9)
Chris@441 328 pdf.RDMCell(35,5, l(:field_author) + ":","L")
Chris@0 329 pdf.SetFontStyle('',9)
Chris@441 330 pdf.RDMCell(60,5, issue.author.to_s,"R")
Chris@0 331 pdf.SetFontStyle('B',9)
Chris@441 332 pdf.RDMCell(35,5, l(:field_category) + ":","L")
Chris@0 333 pdf.SetFontStyle('',9)
Chris@441 334 pdf.RDMCell(60,5, issue.category.to_s,"R")
Chris@441 335 pdf.Ln
Chris@441 336
Chris@0 337 pdf.SetFontStyle('B',9)
Chris@441 338 pdf.RDMCell(35,5, l(:field_created_on) + ":","L")
Chris@0 339 pdf.SetFontStyle('',9)
Chris@441 340 pdf.RDMCell(60,5, format_date(issue.created_on),"R")
Chris@0 341 pdf.SetFontStyle('B',9)
Chris@441 342 pdf.RDMCell(35,5, l(:field_assigned_to) + ":","L")
Chris@0 343 pdf.SetFontStyle('',9)
Chris@441 344 pdf.RDMCell(60,5, issue.assigned_to.to_s,"R")
Chris@0 345 pdf.Ln
Chris@441 346
Chris@0 347 pdf.SetFontStyle('B',9)
Chris@441 348 pdf.RDMCell(35,5, l(:field_updated_on) + ":","LB")
Chris@0 349 pdf.SetFontStyle('',9)
Chris@441 350 pdf.RDMCell(60,5, format_date(issue.updated_on),"RB")
Chris@0 351 pdf.SetFontStyle('B',9)
Chris@441 352 pdf.RDMCell(35,5, l(:field_due_date) + ":","LB")
Chris@0 353 pdf.SetFontStyle('',9)
Chris@441 354 pdf.RDMCell(60,5, format_date(issue.due_date),"RB")
Chris@0 355 pdf.Ln
Chris@441 356
Chris@0 357 for custom_value in issue.custom_field_values
Chris@0 358 pdf.SetFontStyle('B',9)
Chris@441 359 pdf.RDMCell(35,5, custom_value.custom_field.name + ":","L")
Chris@0 360 pdf.SetFontStyle('',9)
Chris@441 361 pdf.RDMMultiCell(155,5, (show_value custom_value),"R")
Chris@0 362 end
Chris@441 363
Chris@507 364 y0 = pdf.GetY
Chris@507 365
Chris@0 366 pdf.SetFontStyle('B',9)
Chris@441 367 pdf.RDMCell(35,5, l(:field_subject) + ":","LT")
Chris@0 368 pdf.SetFontStyle('',9)
Chris@441 369 pdf.RDMMultiCell(155,5, issue.subject,"RT")
Chris@507 370 pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY)
Chris@441 371
Chris@0 372 pdf.SetFontStyle('B',9)
Chris@507 373 pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
Chris@0 374 pdf.SetFontStyle('',9)
Chris@909 375
Chris@909 376 # Set resize image scale
Chris@909 377 pdf.SetImageScale(1.6)
Chris@909 378 pdf.RDMwriteHTMLCell(35+155, 5, 0, 0,
Chris@909 379 issue.description.to_s, issue.attachments, "LRB")
Chris@909 380
Chris@909 381 unless issue.leaf?
Chris@909 382 # for CJK
Chris@909 383 truncate_length = ( l(:general_pdf_encoding).upcase == "UTF-8" ? 90 : 65 )
Chris@909 384
Chris@909 385 pdf.SetFontStyle('B',9)
Chris@909 386 pdf.RDMCell(35+155,5, l(:label_subtask_plural) + ":", "LTR")
Chris@909 387 pdf.Ln
Chris@909 388 issue_list(issue.descendants.sort_by(&:lft)) do |child, level|
Chris@909 389 buf = truncate("#{child.tracker} # #{child.id}: #{child.subject}",
Chris@909 390 :length => truncate_length)
Chris@909 391 level = 10 if level >= 10
Chris@909 392 pdf.SetFontStyle('',8)
Chris@909 393 pdf.RDMCell(35+135,5, (level >=1 ? " " * level : "") + buf, "L")
Chris@909 394 pdf.SetFontStyle('B',8)
Chris@909 395 pdf.RDMCell(20,5, child.status.to_s, "R")
Chris@909 396 pdf.Ln
Chris@909 397 end
Chris@909 398 end
Chris@909 399
Chris@909 400 relations = issue.relations.select { |r| r.other_issue(issue).visible? }
Chris@909 401 unless relations.empty?
Chris@909 402 # for CJK
Chris@909 403 truncate_length = ( l(:general_pdf_encoding).upcase == "UTF-8" ? 80 : 60 )
Chris@909 404
Chris@909 405 pdf.SetFontStyle('B',9)
Chris@909 406 pdf.RDMCell(35+155,5, l(:label_related_issues) + ":", "LTR")
Chris@909 407 pdf.Ln
Chris@909 408 relations.each do |relation|
Chris@909 409 buf = ""
Chris@909 410 buf += "#{l(relation.label_for(issue))} "
Chris@909 411 if relation.delay && relation.delay != 0
Chris@909 412 buf += "(#{l('datetime.distance_in_words.x_days', :count => relation.delay)}) "
Chris@909 413 end
Chris@909 414 if Setting.cross_project_issue_relations?
Chris@909 415 buf += "#{relation.other_issue(issue).project} - "
Chris@909 416 end
Chris@909 417 buf += "#{relation.other_issue(issue).tracker}" +
Chris@909 418 " # #{relation.other_issue(issue).id}: #{relation.other_issue(issue).subject}"
Chris@909 419 buf = truncate(buf, :length => truncate_length)
Chris@909 420 pdf.SetFontStyle('', 8)
Chris@909 421 pdf.RDMCell(35+155-60, 5, buf, "L")
Chris@909 422 pdf.SetFontStyle('B',8)
Chris@909 423 pdf.RDMCell(20,5, relation.other_issue(issue).status.to_s, "")
Chris@909 424 pdf.RDMCell(20,5, format_date(relation.other_issue(issue).start_date), "")
Chris@909 425 pdf.RDMCell(20,5, format_date(relation.other_issue(issue).due_date), "R")
Chris@909 426 pdf.Ln
Chris@909 427 end
Chris@909 428 end
Chris@909 429 pdf.RDMCell(190,5, "", "T")
Chris@0 430 pdf.Ln
Chris@441 431
Chris@441 432 if issue.changesets.any? &&
Chris@441 433 User.current.allowed_to?(:view_changesets, issue.project)
Chris@0 434 pdf.SetFontStyle('B',9)
Chris@441 435 pdf.RDMCell(190,5, l(:label_associated_revisions), "B")
Chris@0 436 pdf.Ln
Chris@0 437 for changeset in issue.changesets
Chris@0 438 pdf.SetFontStyle('B',8)
Chris@507 439 csstr = "#{l(:label_revision)} #{changeset.format_identifier} - "
Chris@507 440 csstr += format_time(changeset.committed_on) + " - " + changeset.author.to_s
Chris@507 441 pdf.RDMCell(190, 5, csstr)
Chris@0 442 pdf.Ln
Chris@0 443 unless changeset.comments.blank?
Chris@0 444 pdf.SetFontStyle('',8)
Chris@909 445 pdf.RDMwriteHTMLCell(190,5,0,0,
Chris@909 446 changeset.comments.to_s, issue.attachments, "")
Chris@441 447 end
Chris@0 448 pdf.Ln
Chris@0 449 end
Chris@0 450 end
Chris@441 451
Chris@0 452 pdf.SetFontStyle('B',9)
Chris@441 453 pdf.RDMCell(190,5, l(:label_history), "B")
Chris@441 454 pdf.Ln
Chris@909 455 indice = 0
Chris@441 456 for journal in issue.journals.find(
Chris@441 457 :all, :include => [:user, :details],
Chris@441 458 :order => "#{Journal.table_name}.created_on ASC")
Chris@909 459 indice = indice + 1
Chris@0 460 pdf.SetFontStyle('B',8)
Chris@441 461 pdf.RDMCell(190,5,
Chris@909 462 "#" + indice.to_s +
Chris@909 463 " - " + format_time(journal.created_on) +
Chris@909 464 " - " + journal.user.name)
Chris@0 465 pdf.Ln
Chris@0 466 pdf.SetFontStyle('I',8)
Chris@0 467 for detail in journal.details
Chris@441 468 pdf.RDMMultiCell(190,5, "- " + show_detail(detail, true))
Chris@0 469 end
Chris@0 470 if journal.notes?
Chris@441 471 pdf.Ln unless journal.details.empty?
Chris@0 472 pdf.SetFontStyle('',8)
Chris@909 473 pdf.RDMwriteHTMLCell(190,5,0,0,
Chris@909 474 journal.notes.to_s, issue.attachments, "")
Chris@441 475 end
Chris@0 476 pdf.Ln
Chris@0 477 end
Chris@441 478
Chris@0 479 if issue.attachments.any?
Chris@0 480 pdf.SetFontStyle('B',9)
Chris@441 481 pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
Chris@0 482 pdf.Ln
Chris@0 483 for attachment in issue.attachments
Chris@0 484 pdf.SetFontStyle('',8)
Chris@441 485 pdf.RDMCell(80,5, attachment.filename)
Chris@441 486 pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
Chris@441 487 pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
Chris@441 488 pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
Chris@0 489 pdf.Ln
Chris@0 490 end
Chris@0 491 end
Chris@0 492 pdf.Output
Chris@0 493 end
chris@22 494
Chris@909 495 # Returns a PDF string of a single wiki page
Chris@909 496 def wiki_to_pdf(page, project)
Chris@909 497 pdf = ITCPDF.new(current_language)
Chris@909 498 pdf.SetTitle("#{project} - #{page.title}")
Chris@909 499 pdf.alias_nb_pages
Chris@909 500 pdf.footer_date = format_date(Date.today)
Chris@909 501 pdf.AddPage
Chris@909 502 pdf.SetFontStyle('B',11)
Chris@909 503 pdf.RDMMultiCell(190,5,
Chris@909 504 "#{project} - #{page.title} - # #{page.content.version}")
Chris@909 505 pdf.Ln
Chris@909 506 # Set resize image scale
Chris@909 507 pdf.SetImageScale(1.6)
Chris@909 508 pdf.SetFontStyle('',9)
Chris@909 509 pdf.RDMwriteHTMLCell(190,5,0,0,
Chris@909 510 page.content.text.to_s, page.attachments, "TLRB")
Chris@909 511 if page.attachments.any?
Chris@909 512 pdf.Ln
Chris@909 513 pdf.SetFontStyle('B',9)
Chris@909 514 pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
Chris@909 515 pdf.Ln
Chris@909 516 for attachment in page.attachments
Chris@909 517 pdf.SetFontStyle('',8)
Chris@909 518 pdf.RDMCell(80,5, attachment.filename)
Chris@909 519 pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
Chris@909 520 pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
Chris@909 521 pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
Chris@909 522 pdf.Ln
Chris@909 523 end
Chris@909 524 end
Chris@909 525 pdf.Output
Chris@909 526 end
Chris@909 527
Chris@441 528 class RDMPdfEncoding
Chris@909 529 def self.rdm_from_utf8(txt, encoding)
Chris@441 530 txt ||= ''
Chris@909 531 txt = Redmine::CodesetUtil.from_utf8(txt, encoding)
Chris@441 532 if txt.respond_to?(:force_encoding)
Chris@441 533 txt.force_encoding('ASCII-8BIT')
Chris@441 534 end
Chris@441 535 txt
Chris@441 536 end
Chris@909 537
Chris@909 538 def self.attach(attachments, filename, encoding)
Chris@909 539 filename_utf8 = Redmine::CodesetUtil.to_utf8(filename, encoding)
Chris@909 540 atta = nil
Chris@909 541 if filename_utf8 =~ /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i
Chris@909 542 atta = Attachment.latest_attach(attachments, filename_utf8)
Chris@909 543 end
Chris@909 544 if atta && atta.readable? && atta.visible?
Chris@909 545 return atta
Chris@909 546 else
Chris@909 547 return nil
Chris@909 548 end
Chris@909 549 end
Chris@441 550 end
Chris@0 551 end
Chris@0 552 end
Chris@0 553 end