OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
fix(pdf-export): cleanup, remove unused code, refactor, update md2pdf
as-op4359d529a9c4
diff --git a/Gemfile b/Gemfileindex f5f88c006cc..0dc24326f2d 100644--- a/Gemfile+++ b/Gemfile@@ -154,7 +154,7 @@ gem 'airbrake', '~> 13.0.0', require: falsegem "hexapdf", "~> 0.32.0"gem 'prawn', '~> 2.2'gem 'prawn-markup', '~> 0.3.0'-gem 'md_to_pdf', git: 'https://github.com/opf/md-to-pdf', ref: '88eda1608248e556c0d6fa5fb5d858510292fe28'+gem 'md_to_pdf', git: 'https://github.com/opf/md-to-pdf', ref: '92e4cd63c322d8e27ae6a9e0811f948493732aa4'# prawn implicitly depends on matrix gem no longer in ruby core with 3.1gem 'matrix', '~> 0.4.2'diff --git a/Gemfile.lock b/Gemfile.lockindex 4f00197a707..39314ae24ef 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -1,7 +1,7 @@GITremote: https://github.com/opf/md-to-pdf- revision: 88eda1608248e556c0d6fa5fb5d858510292fe28- ref: 88eda1608248e556c0d6fa5fb5d858510292fe28+ revision: 92e4cd63c322d8e27ae6a9e0811f948493732aa4+ ref: 92e4cd63c322d8e27ae6a9e0811f948493732aa4specs:md_to_pdf (0.0.15)commonmarker (~> 0.23.6)diff --git a/app/models/work_package/pdf_export/attachments.rb b/app/models/work_package/pdf_export/attachments.rbindex b5012db03b0..682f6d0816f 100644--- a/app/models/work_package/pdf_export/attachments.rb+++ b/app/models/work_package/pdf_export/attachments.rb@@ -29,40 +29,6 @@require 'mini_magick'module WorkPackage::PDFExport::Attachments- ##- # Creates cells for each attachment of the work package- #- def make_attachments_cells(attachments)- # Distribute all attachments on one line, this will work well with up to ~5 attachments.- # more than that will be resized further- available_width = (pdf.bounds.width / attachments.length) * 0.98-- attachments- .map { |attachment| make_attachment_cell attachment, available_width }- .compact- end-- private-- def make_attachment_cell(attachment, available_width)- # We can only include JPG and PNGs, maybe we want to add a text box for other attachments here- return nil unless pdf_embeddable?(attachment)-- # Access the local file. For Carrierwave attachments, this will be blocking.- file_path = attachment.file.local_file.path-- # Let's not include the raw images as the sum of all images can hit the memory limit of the worker process.- # As we do not need the full image size when printing small images into the PDF let's reduce it on the fly.- # It uses CPU and time. However, we don't expect that feature to get used often.- resized_file_path = resize_image(file_path)-- # Fit the image roughly in the center of each cell- pdf.make_cell(image: resized_file_path, fit: [available_width, 125], position: :center)- rescue StandardError => e- Rails.logger.error { "Failed to attach work package image to PDF: #{e} #{e.message}" }- nil- end-def resize_image(file_path)resized_file_path = extend_file_name_in_path(file_path, '__x325')image = MiniMagick::Image.open(file_path)diff --git a/app/models/work_package/pdf_export/common.rb b/app/models/work_package/pdf_export/common.rbindex 6fb5b0d63d2..de056b02493 100644--- a/app/models/work_package/pdf_export/common.rb+++ b/app/models/work_package/pdf_export/common.rb@@ -64,31 +64,6 @@ module WorkPackage::PDFExport::Commonraise ::Exports::ExportError.new messageend- def cell_padding- @cell_padding ||= [2, 5, 2, 5]- end-- def configure_markup- # Do not attempt to fetch images.- # Fetching images can cause errors e.g. a 403 is returned when attempting to fetch from aws with- # a no longer valid token.- # Such an error would cause the whole export to error.- pdf.markup_options = {- image: {- loader: ->(_src) {},- placeholder: "<i>[#{I18n.t('export.image.omitted')}]</i>"- }- }- end-- def current_y_position- OpenStruct.new y: pdf.y, page: pdf.page_number- end-- def position_diff(position_a, position_b)- position_a.y - position_b.y + ((position_b.page - position_a.page) * pdf.bounds.height)- end-def with_margin(opts, &)with_vertical_margin(opts) dopdf.indent(opts[:margin_left] || 0, opts[:margin_right] || 0, &)diff --git a/app/models/work_package/pdf_export/formattable.rb b/app/models/work_package/pdf_export/formattable.rbdeleted file mode 100644index 0cda6dffb01..00000000000--- a/app/models/work_package/pdf_export/formattable.rb+++ /dev/null@@ -1,128 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--module WorkPackage::PDFExport::Formattable- ##- # Writes the formatted work package description into the document.- #- # A border (without one on the top) is painted around the area painted by the description.- #- # @param work_package [WorkPackage] The work package for which the description is to be printed.- # @param markdown [string] The formattable text- # @param label [string|null] The label to print, if any- def write_formattable!(work_package, markdown:, label: WorkPackage.human_attribute_name(attribute))- height = write_formattable_content(work_package, markdown:, label:)-- data = make_formattable_label_row(label) +- make_formattable_border_rows(height, label)-- pdf.table(data, column_widths:)- end-- def write_formattable_content(work_package, markdown:, label: true)- float_with_height_indicator do- pdf.move_down(cell_padding[1])-- pdf.indent(formattable_padding_left(label), cell_padding[3]) do- pdf.markup format_text(markdown, object: work_package, format: :html)- end- end- end-- def float_with_height_indicator- former_position = new_position = current_y_position-- pdf.float do- yield-- new_position = current_y_position- end-- position_diff(former_position, new_position)- end-- def make_formattable_label_row(label)- if label.present?- [[make_formattable_label(label), pdf.make_cell('', borders: [:right], colspan: formattable_colspan)].compact]- else- [[pdf.make_cell('', borders: %i[right left], colspan: formattable_colspan)]]- end- end-- def formattable_padding_left(label)- if label.present?- column_widths.first + cell_padding[1]- else- cell_padding[1]- end- end-- def formattable_padding_right- cell_padding[3]- end-- def make_formattable_border_rows(height, label)- border_row_height = 10-- (height / border_row_height).ceil.times.map do |index|- make_formattable_border_row(border_row_height,- label,- index == (height / border_row_height).ceil - 1)- end- end-- def make_formattable_border_row(border_row_height, label, last)- border_left = if label- [:left]- else- %i[left right]- end-- border_right = [:right]-- if last- border_left << :bottom- border_right << :bottom- end-- if label- [pdf.make_cell('', height: border_row_height, borders: border_left, colspan: 1),- pdf.make_cell('', height: border_row_height, borders: border_right, colspan: formattable_colspan)]- else- [pdf.make_cell('', height: border_row_height, borders: border_left, colspan: formattable_colspan)]- end- end-- def make_formattable_label(label)- pdf.make_cell("#{label}:", borders: [:left], font_style: :bold, padding: cell_padding)- end-- def formattable_colspan- raise NotImplementedError, 'to be implemented where included'- end-enddiff --git a/app/models/work_package/pdf_export/markdown.rb b/app/models/work_package/pdf_export/markdown.rbindex 3255e2c44d4..df05ec4a855 100644--- a/app/models/work_package/pdf_export/markdown.rb+++ b/app/models/work_package/pdf_export/markdown.rb@@ -69,8 +69,11 @@ module WorkPackage::PDFExport::Markdowncase tag.namewhen 'mention'# <mention class="mention" data-id="46012" data-type="work_package" data-text="#46012"></mention>- text = tag.attr('data-text')- result.push(text_hash(text, opts)) if text.present?+ # <mention class="mention" data-id="3" data-type="user" data-text="@Some User">@Some User</mention>+ if tag.text.blank?+ text = tag.attr('data-text')+ result.push(text_hash(text, opts)) if text.present?+ endwhen 'span'text = tag.textresult.push(text_hash(text, opts)) if text.present?diff --git a/app/models/work_package/pdf_export/markdown_field.rb b/app/models/work_package/pdf_export/markdown_field.rbindex 0f34fb03a87..91f2fc1e73f 100644--- a/app/models/work_package/pdf_export/markdown_field.rb+++ b/app/models/work_package/pdf_export/markdown_field.rb@@ -34,20 +34,20 @@ module WorkPackage::PDFExport::MarkdownField# TODO: move page break threshold const to style settings and implement conditional break with height measuringwrite_optional_page_break(100)- write_label! label+ write_field_label! labelwrite_markdown! work_package, markdownend- private-- def write_label!(label)+ def write_field_label!(label)with_margin(label_margins_style) dopdf.formatted_text([label_style.merge({ text: label })])endend+ private+def label_margins_style- { margin_top: 8, margin_bottom: 4 }+ { margin_top: 12, margin_bottom: 8 }enddef label_stylediff --git a/app/models/work_package/pdf_export/page.rb b/app/models/work_package/pdf_export/page.rbnew file mode 100644index 00000000000..42359b0796b--- /dev/null+++ b/app/models/work_package/pdf_export/page.rb@@ -0,0 +1,91 @@+module WorkPackage::PDFExport::Page++ def configure_page_size!(layout)+ pdf.options[:page_size] = 'EXECUTIVE' # TODO: 'A4'?+ pdf.options[:page_layout] = layout+ pdf.options[:top_margin] = page_top_margin+ pdf.options[:bottom_margin] = page_bottom_margin+ end++ def write_logo!+ image_obj, image_info, scale = logo_pdf_image+ pdf.repeat :all do+ top = pdf.bounds.top + page_header_top + (logo_height / 2)+ pdf.embed_image image_obj, image_info, { at: [0, top], scale: }+ end+ end++ def logo_pdf_image+ image_file = Rails.root.join("app/assets/images/logo_openproject.png")+ image_obj, image_info = pdf.build_image_object(image_file)+ scale = [logo_height / image_info.height.to_f, 1].min+ [image_obj, image_info, scale]+ end++ def write_title!+ pdf.title = heading+ pdf.formatted_text([page_heading_style.merge({ text: heading })])+ end++ def write_headers!+ write_logo!+ write_header_user!(User.current) unless User.current.nil?+ end++ def write_header_user!(user)+ draw_repeating_text("#{user.firstname} #{user.lastname}",+ :right, pdf.bounds.top + logo_height, page_header_style)+ end++ def write_footers!+ write_footer_date!+ write_footer_page_nr!+ write_footer_title!+ end++ def write_footer_page_nr!+ draw_repeating_dynamic_text(:center, -page_footer_top, page_footer_style) do+ (pdf.page_number + @page_count).to_s+ end+ end++ def write_footer_title!+ draw_repeating_text(heading, :right, -page_footer_top, page_footer_style)+ end++ def write_footer_date!+ draw_repeating_text(format_date(Time.zone.today), :left, -page_footer_top, page_footer_style)+ end++ def page_header_top+ 20+ end++ def page_bottom_margin+ 60+ end++ def page_footer_top+ 30+ end++ def logo_height+ 20+ end++ def page_top_margin+ 60+ end++ def page_heading_style+ { size: 14, styles: [:bold] }+ end++ def page_header_style+ { size: 8, style: :normal }+ end++ def page_footer_style+ { size: 8, style: :normal }+ end+enddiff --git a/app/models/work_package/pdf_export/work_package_detail.rb b/app/models/work_package/pdf_export/work_package_detail.rbindex e3690a5b869..e28c360a70d 100644--- a/app/models/work_package/pdf_export/work_package_detail.rb+++ b/app/models/work_package/pdf_export/work_package_detail.rb@@ -31,23 +31,27 @@ module WorkPackage::PDFExport::WorkPackageDetaildef write_work_packages_details!(work_packages, id_wp_meta_map)work_packages.each do |work_package|- write_detail!(work_package, id_wp_meta_map[work_package.id][:level_path])+ write_work_package_detail!(work_package, id_wp_meta_map[work_package.id][:level_path])endend- private-- def write_detail!(work_package, level_path)+ def write_work_package_detail!(work_package, level_path)# TODO: move page break threshold const to style settings and implement conditional break with height measuringwrite_optional_page_break(200)with_margin(detail_margins_style) dowrite_work_package_subject! work_package, level_path- write_attributes_table! work_package- write_description! work_package- write_custom_fields! work_package+ write_work_package_detail_content! work_packageendend+ def write_work_package_detail_content!(work_package)+ write_attributes_table! work_package+ write_description! work_package+ write_custom_fields! work_package+ end++ private+def write_work_package_subject!(work_package, level_path)with_margin(subject_margins_style) dopdf_dest = pdf.dest_xyz(0, pdf.y)diff --git a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb b/app/models/work_package/pdf_export/work_package_list_to_pdf.rbindex 7717b8e411e..bf58cbf6099 100644--- a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb+++ b/app/models/work_package/pdf_export/work_package_list_to_pdf.rb@@ -45,6 +45,7 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Queryinclude WorkPackage::PDFExport::Attachmentsinclude WorkPackage::PDFExport::OverviewTableinclude WorkPackage::PDFExport::WorkPackageDetail+ include WorkPackage::PDFExport::Pageattr_accessor :pdf,:options@@ -76,14 +77,7 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Querydef setup_page!self.pdf = get_pdf(current_language)- configure_page_size!- end-- def configure_page_size!- pdf.options[:page_size] = 'EXECUTIVE' # TODO: 'A4'?- pdf.options[:page_layout] = with_descriptions? ? :portrait : :landscape- pdf.options[:top_margin] = page_top_margin- pdf.options[:bottom_margin] = page_bottom_margin+ configure_page_size!(with_descriptions? ? :portrait : :landscape)enddef render_work_packages(work_packages, filename: "pdf_export")@@ -161,11 +155,6 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Queryquery.projectend- def write_title!- pdf.title = heading- pdf.formatted_text([page_heading_style.merge({ text: heading })])- end-def title"#{heading}.pdf"end@@ -180,80 +169,4 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Queryendend- def write_logo!- image_obj, image_info, scale = logo_pdf_image- pdf.repeat :all do- top = pdf.bounds.top + page_header_top + (logo_height / 2)- pdf.embed_image image_obj, image_info, { at: [0, top], scale: }- end- end-- def logo_pdf_image- image_file = Rails.root.join("app/assets/images/logo_openproject.png")- image_obj, image_info = pdf.build_image_object(image_file)- scale = [logo_height / image_info.height.to_f, 1].min- [image_obj, image_info, scale]- end-- def write_headers!- write_logo!- write_header_user!(User.current) unless User.current.nil?- end-- def write_header_user!(user)- draw_repeating_text("#{user.firstname} #{user.lastname}",- :right, pdf.bounds.top + logo_height, page_header_style)- end-- def write_footers!- write_footer_date!- write_footer_page_nr!- write_footer_title!- end-- def write_footer_page_nr!- draw_repeating_dynamic_text(:center, -page_footer_top, page_footer_style) do- (pdf.page_number + @page_count).to_s- end- end-- def write_footer_title!- draw_repeating_text(heading, :right, -page_footer_top, page_footer_style)- end-- def write_footer_date!- draw_repeating_text(format_date(Time.zone.today), :left, -page_footer_top, page_footer_style)- end-- def page_header_top- 20- end-- def page_bottom_margin- 60- end-- def page_footer_top- 30- end-- def logo_height- 20- end-- def page_top_margin- 60- end-- def page_heading_style- { size: 14, styles: [:bold] }- end-- def page_header_style- { size: 8, style: :normal }- end-- def page_footer_style- { size: 8, style: :normal }- endenddiff --git a/app/models/work_package/pdf_export/work_package_to_pdf.rb b/app/models/work_package/pdf_export/work_package_to_pdf.rbindex 2cb6ba2a85a..d296ec86b73 100644--- a/app/models/work_package/pdf_export/work_package_to_pdf.rb+++ b/app/models/work_package/pdf_export/work_package_to_pdf.rb@@ -28,8 +28,9 @@class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporterinclude WorkPackage::PDFExport::Common- include WorkPackage::PDFExport::Formattableinclude WorkPackage::PDFExport::Attachments+ include WorkPackage::PDFExport::WorkPackageDetail+ include WorkPackage::PDFExport::Pageattr_accessor :pdf, :columns@@ -44,89 +45,30 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporterdef initialize(work_package, _options = {})super- self.pdf = get_pdf(current_language)self.columns = ::Query.available_columns(work_package.project)-- configure_markup+ setup_page!enddef export!- write_attributes!- write_changesets!- write_history!- write_attachments!- write_footers!-+ render_work_packagesuccess(pdf.render)end- def make_attribute_row(first_attribute, second_attribute)- [- make_attribute_cells(- first_attribute,- label_options: {- borders: [:left], font_style: :bold, padding: cell_padding- },- value_options: {- borders: [], padding: cell_padding- }- ),- make_attribute_cells(- second_attribute,- label_options: {- borders: [:left], font_style: :bold, padding: cell_padding- },- value_options: {- borders: [:right], padding: cell_padding- }- )- ]- .flatten- end-- def make_attribute_cells(attribute, label_options: {}, value_options: {})- label = pdf.make_cell(- WorkPackage.human_attribute_name(attribute) + ':',- label_options- )-- column = columns.find { |col| col.name == attribute.to_sym }- formatter = formatter_for(column.name)- value_content = formatter.format(work_package)- value = pdf.make_cell(value_content.to_s, value_options)-- [label, value]- end-- def make_attributes- attrs = [- %i[status priority],- %i[author category],- %i[created_at assigned_to],- %i[updated_at due_date]- ]+ private- attrs.map do |first, second|- make_attribute_row first, second- end+ def setup_page!+ self.pdf = get_pdf(current_language)+ @page_count = 0+ configure_page_size!(:portrait)end- def make_plain_custom_fields- work_package.custom_field_values.each do |custom_value|- next if custom_value.custom_field.formattable?-- cf = custom_value.custom_field- name = cf.name || Array(cf.name_translations.first).last || '?'-- label = pdf.make_cell "#{name}:",- borders: [:left], font_style: :bold,- padding: cell_padding- value = pdf.make_cell show_value(custom_value),- colspan: 3,- borders: [:right],- padding: cell_padding- yield [label, value]- end+ def render_work_package+ write_title!+ write_work_package_detail_content!(work_package)+ write_history!+ write_changesets! if show_changesets?+ write_headers!+ write_footers!enddef show_changesets?@@ -134,41 +76,6 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::ExporterUser.current.allowed_to?(:view_changesets, work_package.project)end- def newline!- pdf.move_down 4- end-- def max_width- pdf.bounds.width- end-- def column_widths- [0.2, 0.3, 0.2, 0.3].map do |factor|- max_width * factor- end- end-- def formattable_colspan- 3- end-- def write_footers!- pdf.number_pages format_date(Date.today),- at: [pdf.bounds.left, 0],- style: :italic-- pdf.number_pages "<page>/<total>",- at: [pdf.bounds.right - 25, 0],- style: :italic- end-- def write_title!- pdf.title = heading- pdf.apply_font style: :bold, size: 11- pdf.text "#{heading}: #{work_package.subject}"- pdf.move_down 20- end-def heading"#{work_package.project} - ##{work_package.type} #{work_package.id}"end@@ -177,131 +84,64 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporter"#{heading}.pdf"end- def write_attributes!- write_title!-- data = make_attributes-- data.first.each { |cell| cell.borders << :top } # top horizontal line- data.last.each { |cell| cell.borders << :bottom } # horizontal line after main attrs-- # Render plain custom values- make_plain_custom_fields { |row| data << row }-- pdf.apply_font style: :normal, size: 9- pdf.table(data, column_widths:)-- # Render formattable custom values- work_package.custom_field_values- .select { |cv| cv.custom_field.formattable? }- .each do |custom_value|- write_formattable! work_package,- markdown: custom_value.value,- label: custom_value.custom_field.name- end-- write_formattable! work_package,- markdown: work_package.description,- label: WorkPackage.human_attribute_name(:description)- end-- def write_changesets!- if show_changesets?- newline!-- pdf.apply_font style: :bold, size: 9- pdf.text I18n.t(:label_associated_revisions)- pdf.stroke do- pdf.horizontal_rule- end- newline!-- work_package.changesets.each do |changeset|- pdf.apply_font style: :bold, size: 8- pdf.text(format_time(changeset.committed_on) + ' - ' + changeset.author.to_s)- newline!-- if changeset.comments.present?- pdf.apply_font style: :normal, size: 8- pdf.text changeset.comments.to_s- end-- newline!- end- end- end-def write_history!- pdf.move_down(pdf.font_size * 2)-- pdf.apply_font style: :bold, size: 9- pdf.text I18n.t(:label_history)- pdf.stroke do- pdf.horizontal_rule- end-- newline!-+ write_field_label! I18n.t(:label_history)work_package.journals.includes(:user).order("#{Journal.table_name}.created_at ASC").each do |journal|next if journal.initial?- pdf.apply_font style: :bold, size: 8- pdf.text(format_time(journal.created_at) + ' - ' + journal.user.name)- newline!+ write_history_item! journal+ end+ end- pdf.apply_font style: :italic, size: 8+ def write_history_item!(journal)+ headline = "#{format_time(journal.created_at)} - #{journal.user.name}"+ with_margin(headline_margins_style) do+ pdf.formatted_text([headline_style.merge({ text: headline })])+ end+ with_margin(item_margins_style) dojournal.details.each do |detail|- text = journal- .render_detail(detail, html: false, only_path: false)- .gsub(/\((https?[^)]+)\)$/, "(<link href='\\1'>\\1</link>)")-- pdf.text('- ' + text, inline_format: true)- newline!+ text = journal.render_detail(detail, html: true, only_path: false)+ write_markdown! work_package, "* #{text}"end-if journal.notes?- newline! unless journal.details.empty?-- pdf.apply_font style: :normal, size: 8-- pdf.markup(format_text(journal.notes.to_s, object: work_package, format: :html))+ text = journal.notes.to_s+ write_markdown! work_package, textend-- newline!endend- def write_attachments!- if work_package.attachments.any?- pdf.move_down(pdf.font_size * 2)+ def write_changesets!+ write_field_label!(I18n.t(:label_associated_revisions))+ work_package.changesets.each do |changeset|+ write_changeset_item! changeset+ end+ end- pdf.apply_font style: :bold, size: 9- pdf.text I18n.t(:label_attachment_plural)- pdf.stroke do- pdf.horizontal_rule+ def write_changeset_item!(changeset)+ headline = "#{format_time(changeset.committed_on)} - #{changeset.author.to_s}"+ with_margin(headline_margins_style) do+ pdf.formatted_text([headline_style.merge({ text: headline })])+ end+ with_margin(item_margins_style) do+ if changeset.comments.present?+ pdf.formatted_text([headline_style.merge({ text: changeset.comments.to_s })])end- newline!+ end+ end- pdf.apply_font style: :normal, size: 8+ def headline_margins_style+ { margin_top: 4, margin_bottom: 4 }+ end- data = work_package.attachments.map do |attachment|- [- attachment.filename,- number_to_human_size(attachment.filesize, precision: 3),- format_date(attachment.created_at),- attachment.author.name- ]- end+ def headline_style+ { size: 9, styles: [:bold] }+ end- table_width = max_width- pdf.table(data, width: table_width - 1) do- cells.padding = [2, 5, 2, 5]- cells.borders = []+ def item_margins_style+ { margin_left: 10 }+ end- column(0).width = (table_width * 0.5).to_i- column(1).align = :right- column(3).align = :right- end- end+ def item_style+ { size: 9, styles: [:italic] }endend