@@ -198,16 +198,28 module Redmine | |||
|
198 | 198 | pdf.SetTitle(title) |
|
199 | 199 | pdf.alias_nb_pages |
|
200 | 200 | pdf.footer_date = format_date(Date.today) |
|
201 | pdf.SetAutoPageBreak(false) | |
|
201 | 202 | pdf.AddPage("L") |
|
202 | ||
|
203 | row_height = 6 | |
|
203 | ||
|
204 | # Landscape A4 = 210 x 297 mm | |
|
205 | page_height = 210 | |
|
206 | page_width = 297 | |
|
207 | right_margin = 10 | |
|
208 | bottom_margin = 20 | |
|
209 | col_id_width = 10 | |
|
210 | row_height = 5 | |
|
211 | ||
|
212 | # column widths | |
|
213 | table_width = page_width - right_margin - 10 # fixed left margin | |
|
204 | 214 | col_width = [] |
|
205 | 215 | unless query.columns.empty? |
|
206 |
col_width = query.columns.collect |
|
|
207 | ratio = 262.0 / col_width.inject(0) {|s,w| s += w} | |
|
216 | col_width = query.columns.collect do |c| | |
|
217 | (c.name == :subject || (c.is_a?(QueryCustomFieldColumn) && ['string', 'text'].include?(c.custom_field.field_format)))? 4.0 : 1.0 | |
|
218 | end | |
|
219 | ratio = (table_width - col_id_width) / col_width.inject(0) {|s,w| s += w} | |
|
208 | 220 | col_width = col_width.collect {|w| w * ratio} |
|
209 | 221 | end |
|
210 | ||
|
222 | ||
|
211 | 223 | # title |
|
212 | 224 | pdf.SetFontStyle('B',11) |
|
213 | 225 | pdf.RDMCell(190,10, title) |
@@ -216,7 +228,7 module Redmine | |||
|
216 | 228 | # headers |
|
217 | 229 | pdf.SetFontStyle('B',8) |
|
218 | 230 | pdf.SetFillColor(230, 230, 230) |
|
219 |
pdf.RDMCell( |
|
|
231 | pdf.RDMCell(col_id_width, row_height, "#", 1, 0, 'C', 1) | |
|
220 | 232 | query.columns.each_with_index do |column, i| |
|
221 | 233 | pdf.RDMCell(col_width[i], row_height, column.caption, 1, 0, 'L', 1) |
|
222 | 234 | end |
@@ -236,8 +248,8 module Redmine | |||
|
236 | 248 | pdf.SetFontStyle('',8) |
|
237 | 249 | previous_group = group |
|
238 | 250 | end |
|
239 | pdf.RDMCell(15, row_height, issue.id.to_s, 1, 0, 'L', 1) | |
|
240 |
query.columns.e |
|
|
251 | # fetch all the row values | |
|
252 | col_values = query.columns.collect do |column| | |
|
241 | 253 | s = if column.is_a?(QueryCustomFieldColumn) |
|
242 | 254 | cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id} |
|
243 | 255 | show_value(cv) |
@@ -251,17 +263,63 module Redmine | |||
|
251 | 263 | value |
|
252 | 264 | end |
|
253 | 265 | end |
|
254 | pdf.RDMCell(col_width[i], row_height, s.to_s, 1, 0, 'L', 1) | |
|
266 | s.to_s | |
|
255 | 267 | end |
|
256 |
|
|
|
268 | ||
|
269 | # render it off-page to find the max height used | |
|
270 | base_x = pdf.GetX | |
|
271 | base_y = pdf.GetY | |
|
272 | pdf.SetY(2 * page_height) | |
|
273 | max_height = issues_to_pdf_write_cells(pdf, col_values, col_width, row_height) | |
|
274 | pdf.SetXY(base_x, base_y) | |
|
275 | ||
|
276 | # make new page if it doesn't fit on the current one | |
|
277 | space_left = page_height - base_y - bottom_margin | |
|
278 | if max_height > space_left | |
|
279 | pdf.AddPage("L") | |
|
280 | base_x = pdf.GetX | |
|
281 | base_y = pdf.GetY | |
|
282 | end | |
|
283 | ||
|
284 | # write the cells on page | |
|
285 | pdf.RDMCell(col_id_width, row_height, issue.id.to_s, "T", 0, 'C', 1) | |
|
286 | issues_to_pdf_write_cells(pdf, col_values, col_width, row_height) | |
|
287 | issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width) | |
|
288 | pdf.SetY(base_y + max_height); | |
|
257 | 289 | end |
|
290 | ||
|
258 | 291 | if issues.size == Setting.issues_export_limit.to_i |
|
259 | 292 | pdf.SetFontStyle('B',10) |
|
260 | 293 | pdf.RDMCell(0, row_height, '...') |
|
261 | 294 | end |
|
262 | 295 | pdf.Output |
|
263 | 296 | end |
|
264 | ||
|
297 | ||
|
298 | # Renders MultiCells and returns the maximum height used | |
|
299 | def issues_to_pdf_write_cells(pdf, col_values, col_widths, row_height) | |
|
300 | base_y = pdf.GetY | |
|
301 | max_height = row_height | |
|
302 | col_values.each_with_index do |column, i| | |
|
303 | col_x = pdf.GetX | |
|
304 | pdf.RDMMultiCell(col_widths[i], row_height, col_values[i], "T", 'L', 1) | |
|
305 | max_height = (pdf.GetY - base_y) if (pdf.GetY - base_y) > max_height | |
|
306 | pdf.SetXY(col_x + col_widths[i], base_y); | |
|
307 | end | |
|
308 | return max_height | |
|
309 | end | |
|
310 | ||
|
311 | # Draw lines to close the row (MultiCell border drawing in not uniform) | |
|
312 | def issues_to_pdf_draw_borders(pdf, top_x, top_y, lower_y, id_width, col_widths) | |
|
313 | col_x = top_x + id_width | |
|
314 | pdf.Line(col_x, top_y, col_x, lower_y) # id right border | |
|
315 | col_widths.each do |width| | |
|
316 | col_x += width | |
|
317 | pdf.Line(col_x, top_y, col_x, lower_y) # columns right border | |
|
318 | end | |
|
319 | pdf.Line(top_x, top_y, top_x, lower_y) # left border | |
|
320 | pdf.Line(top_x, lower_y, col_x, lower_y) # bottom border | |
|
321 | end | |
|
322 | ||
|
265 | 323 | # Returns a PDF string of a single issue |
|
266 | 324 | def issue_to_pdf(issue) |
|
267 | 325 | if l(:general_pdf_encoding).upcase != 'UTF-8' |
@@ -273,14 +331,12 module Redmine | |||
|
273 | 331 | pdf.alias_nb_pages |
|
274 | 332 | pdf.footer_date = format_date(Date.today) |
|
275 | 333 | pdf.AddPage |
|
276 | ||
|
277 | pdf.SetFontStyle('B',11) | |
|
278 | pdf.RDMCell(190,10, | |
|
279 | "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}") | |
|
334 | pdf.SetFontStyle('B',11) | |
|
335 | pdf.RDMMultiCell(190,5, "#{issue.project} - #{issue.tracker} # #{issue.id}: #{issue.subject}") | |
|
280 | 336 | pdf.Ln |
|
281 | ||
|
337 | ||
|
282 | 338 | y0 = pdf.GetY |
|
283 | ||
|
339 | ||
|
284 | 340 | pdf.SetFontStyle('B',9) |
|
285 | 341 | pdf.RDMCell(35,5, l(:field_status) + ":","LT") |
|
286 | 342 | pdf.SetFontStyle('',9) |
@@ -329,18 +385,17 module Redmine | |||
|
329 | 385 | end |
|
330 | 386 | |
|
331 | 387 | pdf.SetFontStyle('B',9) |
|
332 |
pdf.RDMCell(35,5, l(:field_subject) + ":","LT |
|
|
388 | pdf.RDMCell(35,5, l(:field_subject) + ":","LT") | |
|
333 | 389 | pdf.SetFontStyle('',9) |
|
334 |
pdf.RDMCell(155,5, issue.subject,"RT |
|
|
335 | pdf.Ln | |
|
336 | ||
|
390 | pdf.RDMMultiCell(155,5, issue.subject,"RT") | |
|
391 | ||
|
337 | 392 | pdf.SetFontStyle('B',9) |
|
338 | pdf.RDMCell(35,5, l(:field_description) + ":") | |
|
393 | pdf.RDMCell(35,5, l(:field_description) + ":","LT") | |
|
339 | 394 | pdf.SetFontStyle('',9) |
|
340 |
pdf.RDMMultiCell(155,5, issue.description.to_s," |
|
|
341 | ||
|
395 | pdf.RDMMultiCell(155,5, issue.description.to_s,"RT") | |
|
396 | ||
|
342 | 397 | pdf.Line(pdf.GetX, y0, pdf.GetX, pdf.GetY) |
|
343 |
pdf.Line(pdf.GetX, pdf.GetY, |
|
|
398 | pdf.Line(pdf.GetX, pdf.GetY, pdf.GetX + 190, pdf.GetY) | |
|
344 | 399 | pdf.Ln |
|
345 | 400 | |
|
346 | 401 | if issue.changesets.any? && |
@@ -373,10 +428,10 module Redmine | |||
|
373 | 428 | pdf.Ln |
|
374 | 429 | pdf.SetFontStyle('I',8) |
|
375 | 430 | for detail in journal.details |
|
376 | pdf.RDMCell(190,5, "- " + show_detail(detail, true)) | |
|
377 | pdf.Ln | |
|
431 | pdf.RDMMultiCell(190,5, "- " + show_detail(detail, true)) | |
|
378 | 432 | end |
|
379 | 433 | if journal.notes? |
|
434 | pdf.Ln unless journal.details.empty? | |
|
380 | 435 | pdf.SetFontStyle('',8) |
|
381 | 436 | pdf.RDMMultiCell(190,5, journal.notes.to_s) |
|
382 | 437 | end |
General Comments 0
You need to be logged in to leave comments.
Login now