You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wiki_pdf_helper.rb 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2017 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. module Redmine
  20. module Export
  21. module PDF
  22. module WikiPdfHelper
  23. # Returns a PDF string of a set of wiki pages
  24. def wiki_pages_to_pdf(pages, project)
  25. pdf = Redmine::Export::PDF::ITCPDF.new(current_language)
  26. pdf.set_title(project.name)
  27. pdf.alias_nb_pages
  28. pdf.footer_date = format_date(User.current.today)
  29. pdf.add_page
  30. pdf.SetFontStyle('B',11)
  31. pdf.RDMMultiCell(190,5, project.name)
  32. pdf.ln
  33. # Set resize image scale
  34. pdf.set_image_scale(1.6)
  35. pdf.SetFontStyle('',9)
  36. write_page_hierarchy(pdf, pages.group_by(&:parent_id))
  37. pdf.output
  38. end
  39. # Returns a PDF string of a single wiki page
  40. def wiki_page_to_pdf(page, project)
  41. pdf = ITCPDF.new(current_language)
  42. pdf.set_title("#{project} - #{page.title}")
  43. pdf.alias_nb_pages
  44. pdf.footer_date = format_date(User.current.today)
  45. pdf.add_page
  46. pdf.SetFontStyle('B',11)
  47. pdf.RDMMultiCell(190,5,
  48. "#{project} - #{page.title} - # #{page.content.version}")
  49. pdf.ln
  50. # Set resize image scale
  51. pdf.set_image_scale(1.6)
  52. pdf.SetFontStyle('',9)
  53. write_wiki_page(pdf, page)
  54. pdf.output
  55. end
  56. def write_page_hierarchy(pdf, pages, node=nil, level=0)
  57. if pages[node]
  58. pages[node].each do |page|
  59. unless level == 0 && page == pages[node].first
  60. pdf.add_page
  61. end
  62. pdf.bookmark page.title, level
  63. write_wiki_page(pdf, page)
  64. write_page_hierarchy(pdf, pages, page.id, level + 1) if pages[page.id]
  65. end
  66. end
  67. end
  68. def write_wiki_page(pdf, page)
  69. text = textilizable(page.content, :text,
  70. :only_path => false,
  71. :edit_section_links => false,
  72. :headings => false,
  73. :inline_attachments => false
  74. )
  75. pdf.RDMwriteFormattedCell(190,5,'','', text, page.attachments, 0)
  76. if page.attachments.any?
  77. pdf.ln(5)
  78. pdf.SetFontStyle('B',9)
  79. pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
  80. pdf.ln
  81. for attachment in page.attachments
  82. pdf.SetFontStyle('',8)
  83. pdf.RDMCell(80,5, attachment.filename)
  84. pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
  85. pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
  86. pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
  87. pdf.ln
  88. end
  89. end
  90. end
  91. end
  92. end
  93. end
  94. end