1
|
# encoding: utf-8
|
2
|
#
|
3
|
# Redmine - project management software
|
4
|
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
5
|
#
|
6
|
# This program is free software; you can redistribute it and/or
|
7
|
# modify it under the terms of the GNU General Public License
|
8
|
# as published by the Free Software Foundation; either version 2
|
9
|
# of the License, or (at your option) any later version.
|
10
|
#
|
11
|
# This program is distributed in the hope that it will be useful,
|
12
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
# GNU General Public License for more details.
|
15
|
#
|
16
|
# You should have received a copy of the GNU General Public License
|
17
|
# along with this program; if not, write to the Free Software
|
18
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19
|
|
20
|
module Redmine
|
21
|
module Export
|
22
|
module PDF
|
23
|
module WikiPdfHelper
|
24
|
# Returns a PDF string of a set of wiki pages
|
25
|
def wiki_pages_to_pdf(pages, project)
|
26
|
pdf = Redmine::Export::PDF::ITCPDF.new(current_language)
|
27
|
#pdf.set_title(project.name)
|
28
|
pdf.alias_nb_pages
|
29
|
#pdf.footer_date = format_date(Date.today)
|
30
|
pdf.add_page
|
31
|
pdf.SetFontStyle('B',11)
|
32
|
pdf.RDMMultiCell(190,5, project.name)
|
33
|
pdf.ln
|
34
|
# Set resize image scale
|
35
|
pdf.set_image_scale(1.6)
|
36
|
pdf.SetFontStyle('',9)
|
37
|
write_page_hierarchy(pdf, pages.group_by(&:parent_id))
|
38
|
pdf.output
|
39
|
end
|
40
|
|
41
|
# Returns a PDF string of a single wiki page
|
42
|
def wiki_page_to_pdf(page, project)
|
43
|
pdf = ITCPDF.new(current_language)
|
44
|
#pdf.set_title("#{project} - #{page.title}")
|
45
|
pdf.alias_nb_pages
|
46
|
#pdf.footer_date = format_date(Date.today)
|
47
|
pdf.add_page
|
48
|
pdf.SetFontStyle('B',11)
|
49
|
#pdf.RDMMultiCell(190,5,
|
50
|
# "#{project} - #{page.title} - # #{page.content.version}")
|
51
|
pdf.ln
|
52
|
# Set resize image scale
|
53
|
pdf.set_image_scale(1.6)
|
54
|
pdf.SetFontStyle('',9)
|
55
|
write_wiki_page(pdf, page)
|
56
|
pdf.output
|
57
|
end
|
58
|
|
59
|
def write_page_hierarchy(pdf, pages, node=nil, level=0)
|
60
|
if pages[node]
|
61
|
pages[node].each do |page|
|
62
|
unless level == 0 && page == pages[node].first
|
63
|
pdf.add_page
|
64
|
end
|
65
|
pdf.bookmark page.title, level
|
66
|
write_wiki_page(pdf, page)
|
67
|
write_page_hierarchy(pdf, pages, page.id, level + 1) if pages[page.id]
|
68
|
end
|
69
|
end
|
70
|
end
|
71
|
|
72
|
def write_wiki_page(pdf, page)
|
73
|
text = textilizable(page.content, :text,
|
74
|
:only_path => false,
|
75
|
:edit_section_links => false,
|
76
|
:headings => false,
|
77
|
:inline_attachments => false
|
78
|
)
|
79
|
pdf.RDMwriteFormattedCell(190,5,'','', text, page.attachments, 0)
|
80
|
#if page.attachments.any?
|
81
|
# pdf.ln(5)
|
82
|
# pdf.SetFontStyle('B',9)
|
83
|
# pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
|
84
|
# pdf.ln
|
85
|
# for attachment in page.attachments
|
86
|
# pdf.SetFontStyle('',8)
|
87
|
# pdf.RDMCell(80,5, attachment.filename)
|
88
|
# pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
|
89
|
# pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
|
90
|
# pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
|
91
|
# pdf.ln
|
92
|
# end
|
93
|
#end
|
94
|
end
|
95
|
end
|
96
|
end
|
97
|
end
|
98
|
end
|