Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
a74517b9
Commit
a74517b9
authored
May 20, 2011
by
Eric Davis
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'hufocf/feature/357-wrap-text-in-pdf'
parents
eaa53820
4662b817
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
20 deletions
+86
-20
pdf.rb
lib/redmine/export/pdf.rb
+86
-20
No files found.
lib/redmine/export/pdf.rb
View file @
a74517b9
...
@@ -88,7 +88,7 @@ module Redmine
...
@@ -88,7 +88,7 @@ module Redmine
end
end
end
end
def
Cell
(
w
,
h
=
0
,
txt
=
''
,
border
=
0
,
ln
=
0
,
align
=
''
,
fill
=
0
,
link
=
''
)
def
fix_text_encoding
(
txt
)
@ic
||=
Iconv
.
new
(
l
(
:general_pdf_encoding
),
'UTF-8'
)
@ic
||=
Iconv
.
new
(
l
(
:general_pdf_encoding
),
'UTF-8'
)
# these quotation marks are not correctly rendered in the pdf
# these quotation marks are not correctly rendered in the pdf
txt
=
txt
.
gsub
(
/[“�]/
,
'"'
)
if
txt
txt
=
txt
.
gsub
(
/[“�]/
,
'"'
)
if
txt
...
@@ -100,7 +100,15 @@ module Redmine
...
@@ -100,7 +100,15 @@ module Redmine
rescue
rescue
txt
txt
end
||
''
end
||
''
super
w
,
h
,
txt
,
border
,
ln
,
align
,
fill
,
link
return
txt
end
def
Cell
(
w
,
h
=
0
,
txt
=
''
,
border
=
0
,
ln
=
0
,
align
=
''
,
fill
=
0
,
link
=
''
)
super
w
,
h
,
fix_text_encoding
(
txt
),
border
,
ln
,
align
,
fill
,
link
end
def
MultiCell
(
w
,
h
=
0
,
txt
=
''
,
border
=
0
,
align
=
''
,
fill
=
0
)
super
w
,
h
,
fix_text_encoding
(
txt
),
border
,
align
,
fill
end
end
def
Footer
def
Footer
...
@@ -122,13 +130,25 @@ module Redmine
...
@@ -122,13 +130,25 @@ module Redmine
pdf
.
SetTitle
(
title
)
pdf
.
SetTitle
(
title
)
pdf
.
AliasNbPages
pdf
.
AliasNbPages
pdf
.
footer_date
=
format_date
(
Date
.
today
)
pdf
.
footer_date
=
format_date
(
Date
.
today
)
pdf
.
SetAutoPageBreak
(
false
)
pdf
.
AddPage
(
"L"
)
pdf
.
AddPage
(
"L"
)
row_height
=
6
# Landscape A4 = 210 x 297 mm
page_height
=
210
page_width
=
297
right_margin
=
10
bottom_margin
=
20
col_id_width
=
10
row_height
=
5
# column widths
table_width
=
page_width
-
right_margin
-
10
# fixed left margin
col_width
=
[]
col_width
=
[]
unless
query
.
columns
.
empty?
unless
query
.
columns
.
empty?
col_width
=
query
.
columns
.
collect
{
|
column
|
column
.
name
==
:subject
?
4.0
:
1.0
}
col_width
=
query
.
columns
.
collect
do
|
c
|
ratio
=
262.0
/
col_width
.
inject
(
0
)
{
|
s
,
w
|
s
+=
w
}
(
c
.
name
==
:subject
||
(
c
.
is_a?
(
QueryCustomFieldColumn
)
&&
[
'string'
,
'text'
].
include?
(
c
.
custom_field
.
field_format
)))?
4.0
:
1.0
end
ratio
=
(
table_width
-
col_id_width
)
/
col_width
.
inject
(
0
)
{
|
s
,
w
|
s
+=
w
}
col_width
=
col_width
.
collect
{
|
w
|
w
*
ratio
}
col_width
=
col_width
.
collect
{
|
w
|
w
*
ratio
}
end
end
...
@@ -140,7 +160,7 @@ module Redmine
...
@@ -140,7 +160,7 @@ module Redmine
# headers
# headers
pdf
.
SetFontStyle
(
'B'
,
8
)
pdf
.
SetFontStyle
(
'B'
,
8
)
pdf
.
SetFillColor
(
230
,
230
,
230
)
pdf
.
SetFillColor
(
230
,
230
,
230
)
pdf
.
Cell
(
15
,
row_height
,
"#"
,
1
,
0
,
'L
'
,
1
)
pdf
.
Cell
(
col_id_width
,
row_height
,
"#"
,
1
,
0
,
'C
'
,
1
)
query
.
columns
.
each_with_index
do
|
column
,
i
|
query
.
columns
.
each_with_index
do
|
column
,
i
|
pdf
.
Cell
(
col_width
[
i
],
row_height
,
column
.
caption
,
1
,
0
,
'L'
,
1
)
pdf
.
Cell
(
col_width
[
i
],
row_height
,
column
.
caption
,
1
,
0
,
'L'
,
1
)
end
end
...
@@ -159,8 +179,9 @@ module Redmine
...
@@ -159,8 +179,9 @@ module Redmine
pdf
.
SetFontStyle
(
''
,
8
)
pdf
.
SetFontStyle
(
''
,
8
)
previous_group
=
group
previous_group
=
group
end
end
pdf
.
Cell
(
15
,
row_height
,
issue
.
id
.
to_s
,
1
,
0
,
'L'
,
1
)
query
.
columns
.
each_with_index
do
|
column
,
i
|
# fetch all the row values
col_values
=
query
.
columns
.
collect
do
|
column
|
s
=
if
column
.
is_a?
(
QueryCustomFieldColumn
)
s
=
if
column
.
is_a?
(
QueryCustomFieldColumn
)
cv
=
issue
.
custom_values
.
detect
{
|
v
|
v
.
custom_field_id
==
column
.
custom_field
.
id
}
cv
=
issue
.
custom_values
.
detect
{
|
v
|
v
.
custom_field_id
==
column
.
custom_field
.
id
}
show_value
(
cv
)
show_value
(
cv
)
...
@@ -174,17 +195,63 @@ module Redmine
...
@@ -174,17 +195,63 @@ module Redmine
value
value
end
end
end
end
pdf
.
Cell
(
col_width
[
i
],
row_height
,
s
.
to_s
,
1
,
0
,
'L'
,
1
)
s
.
to_s
end
end
pdf
.
Ln
# render it off-page to find the max height used
base_x
=
pdf
.
GetX
base_y
=
pdf
.
GetY
pdf
.
SetY
(
2
*
page_height
)
max_height
=
issues_to_pdf_write_cells
(
pdf
,
col_values
,
col_width
,
row_height
)
pdf
.
SetXY
(
base_x
,
base_y
)
# make new page if it doesn't fit on the current one
space_left
=
page_height
-
base_y
-
bottom_margin
if
max_height
>
space_left
pdf
.
AddPage
(
"L"
)
base_x
=
pdf
.
GetX
base_y
=
pdf
.
GetY
end
# write the cells on page
pdf
.
Cell
(
col_id_width
,
row_height
,
issue
.
id
.
to_s
,
"T"
,
0
,
'C'
,
1
)
issues_to_pdf_write_cells
(
pdf
,
col_values
,
col_width
,
row_height
)
issues_to_pdf_draw_borders
(
pdf
,
base_x
,
base_y
,
base_y
+
max_height
,
col_id_width
,
col_width
)
pdf
.
SetY
(
base_y
+
max_height
);
end
end
if
issues
.
size
==
Setting
.
issues_export_limit
.
to_i
if
issues
.
size
==
Setting
.
issues_export_limit
.
to_i
pdf
.
SetFontStyle
(
'B'
,
10
)
pdf
.
SetFontStyle
(
'B'
,
10
)
pdf
.
Cell
(
0
,
row_height
,
'...'
)
pdf
.
Cell
(
0
,
row_height
,
'...'
)
end
end
pdf
.
Output
pdf
.
Output
end
end
# Renders MultiCells and returns the maximum height used
def
issues_to_pdf_write_cells
(
pdf
,
col_values
,
col_widths
,
row_height
)
base_y
=
pdf
.
GetY
max_height
=
row_height
col_values
.
each_with_index
do
|
column
,
i
|
col_x
=
pdf
.
GetX
pdf
.
MultiCell
(
col_widths
[
i
],
row_height
,
col_values
[
i
],
"T"
,
'L'
,
1
)
max_height
=
(
pdf
.
GetY
-
base_y
)
if
(
pdf
.
GetY
-
base_y
)
>
max_height
pdf
.
SetXY
(
col_x
+
col_widths
[
i
],
base_y
);
end
return
max_height
end
# Draw lines to close the row (MultiCell border drawing in not uniform)
def
issues_to_pdf_draw_borders
(
pdf
,
top_x
,
top_y
,
lower_y
,
id_width
,
col_widths
)
col_x
=
top_x
+
id_width
pdf
.
Line
(
col_x
,
top_y
,
col_x
,
lower_y
)
# id right border
col_widths
.
each
do
|
width
|
col_x
+=
width
pdf
.
Line
(
col_x
,
top_y
,
col_x
,
lower_y
)
# columns right border
end
pdf
.
Line
(
top_x
,
top_y
,
top_x
,
lower_y
)
# left border
pdf
.
Line
(
top_x
,
lower_y
,
col_x
,
lower_y
)
# bottom border
end
# Returns a PDF string of a single issue
# Returns a PDF string of a single issue
def
issue_to_pdf
(
issue
)
def
issue_to_pdf
(
issue
)
pdf
=
IFPDF
.
new
(
current_language
)
pdf
=
IFPDF
.
new
(
current_language
)
...
@@ -194,7 +261,7 @@ module Redmine
...
@@ -194,7 +261,7 @@ module Redmine
pdf
.
AddPage
pdf
.
AddPage
pdf
.
SetFontStyle
(
'B'
,
11
)
pdf
.
SetFontStyle
(
'B'
,
11
)
pdf
.
Cell
(
190
,
10
,
"
#{
issue
.
project
}
-
#{
issue
.
tracker
}
#
#{
issue
.
id
}
:
#{
issue
.
subject
}
"
)
pdf
.
MultiCell
(
190
,
5
,
"
#{
issue
.
project
}
-
#{
issue
.
tracker
}
#
#{
issue
.
id
}
:
#{
issue
.
subject
}
"
)
pdf
.
Ln
pdf
.
Ln
y0
=
pdf
.
GetY
y0
=
pdf
.
GetY
...
@@ -247,18 +314,17 @@ module Redmine
...
@@ -247,18 +314,17 @@ module Redmine
end
end
pdf
.
SetFontStyle
(
'B'
,
9
)
pdf
.
SetFontStyle
(
'B'
,
9
)
pdf
.
Cell
(
35
,
5
,
l
(
:field_subject
)
+
":"
,
"LT
B
"
)
pdf
.
Cell
(
35
,
5
,
l
(
:field_subject
)
+
":"
,
"LT"
)
pdf
.
SetFontStyle
(
''
,
9
)
pdf
.
SetFontStyle
(
''
,
9
)
pdf
.
Cell
(
155
,
5
,
issue
.
subject
,
"RTB"
)
pdf
.
MultiCell
(
155
,
5
,
issue
.
subject
,
"RT"
)
pdf
.
Ln
pdf
.
SetFontStyle
(
'B'
,
9
)
pdf
.
SetFontStyle
(
'B'
,
9
)
pdf
.
Cell
(
35
,
5
,
l
(
:field_description
)
+
":"
)
pdf
.
Cell
(
35
,
5
,
l
(
:field_description
)
+
":"
,
"LT"
)
pdf
.
SetFontStyle
(
''
,
9
)
pdf
.
SetFontStyle
(
''
,
9
)
pdf
.
MultiCell
(
155
,
5
,
issue
.
description
.
to_s
,
"
BR
"
)
pdf
.
MultiCell
(
155
,
5
,
issue
.
description
.
to_s
,
"
RT
"
)
pdf
.
Line
(
pdf
.
GetX
,
y0
,
pdf
.
GetX
,
pdf
.
GetY
)
pdf
.
Line
(
pdf
.
GetX
,
y0
,
pdf
.
GetX
,
pdf
.
GetY
)
pdf
.
Line
(
pdf
.
GetX
,
pdf
.
GetY
,
17
0
,
pdf
.
GetY
)
pdf
.
Line
(
pdf
.
GetX
,
pdf
.
GetY
,
pdf
.
GetX
+
19
0
,
pdf
.
GetY
)
pdf
.
Ln
pdf
.
Ln
if
issue
.
changesets
.
any?
&&
User
.
current
.
allowed_to?
(
:view_changesets
,
issue
.
project
)
if
issue
.
changesets
.
any?
&&
User
.
current
.
allowed_to?
(
:view_changesets
,
issue
.
project
)
...
@@ -286,10 +352,10 @@ module Redmine
...
@@ -286,10 +352,10 @@ module Redmine
pdf
.
Ln
pdf
.
Ln
pdf
.
SetFontStyle
(
'I'
,
8
)
pdf
.
SetFontStyle
(
'I'
,
8
)
for
detail
in
journal
.
details
for
detail
in
journal
.
details
pdf
.
Cell
(
190
,
5
,
"- "
+
show_detail
(
detail
,
true
))
pdf
.
MultiCell
(
190
,
5
,
"- "
+
show_detail
(
detail
,
true
))
pdf
.
Ln
end
end
if
journal
.
notes?
if
journal
.
notes?
pdf
.
Ln
unless
journal
.
details
.
empty?
pdf
.
SetFontStyle
(
''
,
8
)
pdf
.
SetFontStyle
(
''
,
8
)
pdf
.
MultiCell
(
190
,
5
,
journal
.
notes
.
to_s
)
pdf
.
MultiCell
(
190
,
5
,
journal
.
notes
.
to_s
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment