From bf0548ecfea89cf9a60a9c965440632f5cbfbdb8 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 24 Nov 2024 01:32:24 +0100 Subject: [PATCH] Improve pdf more --- app/models/pdf_documents/customer_report.rb | 49 ++++++++++++--------- config/initializers/prawn.rb | 9 ++-- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/models/pdf_documents/customer_report.rb b/app/models/pdf_documents/customer_report.rb index bb7311a..95a0154 100644 --- a/app/models/pdf_documents/customer_report.rb +++ b/app/models/pdf_documents/customer_report.rb @@ -5,25 +5,6 @@ module PdfDocuments private def generate - @prawn_document.repeat(:all) do - # @prawn_document.bounding_box([ 0, 790 ], width: 200) do - # logo - # end - # @prawn_document.formatted_text_box([ { - # text: "Dieses Dokument wurd am #{Time.current.strftime('%d %B %Y')} um #{Time.current.strftime('%H:%M:%S')} erstellt.", - # size: 8, - # align: :right - # } ], - # at: [ 0, -15 ], - # width: 200 - # ) - @prawn_document.draw_text "#{I18n.l params.report.updated_at.to_date} #{params.report.name}", at: [ 0, 770 ] - @prawn_document.font_size(8) do - @prawn_document.draw_text("Dieses Dokument wurd am #{Time.current.strftime('%d %B %Y')} um #{Time.current.strftime('%H:%M:%S')} erstellt.", at: [ 0, -15 ]) - end - end - logo - move_down 20 heading1 params.report.name rich_text params.report.comment @pages = {} @@ -53,13 +34,41 @@ module PdfDocuments } @prawn_document.number_pages string, options + @prawn_document.repeat(:all) do + # @prawn_document.bounding_box([ 0, 790 ], width: 200) do + # logo + # end + # @prawn_document.formatted_text_box([ { + # text: "Dieses Dokument wurd am #{Time.current.strftime('%d %B %Y')} um #{Time.current.strftime('%H:%M:%S')} erstellt.", + # size: 8, + # align: :right + # } ], + # at: [ 0, -15 ], + # width: 200 + # ) + @prawn_document.text_box "#{params.report.name}", at: [ 150, 777 ], inline_format: true, width: 300 + @prawn_document.text_box "#{I18n.l params.report.updated_at.to_date, format: :long}", at: [ 0, 777 ], inline_format: true, width: 516, align: :right + @prawn_document.bounding_box([-10, 800], width: 200, height: 200) do + logo + end + @prawn_document.font_size(8) do + @prawn_document.draw_text("Dieses Dokument wurd am #{Time.current.strftime('%d %B %Y')} um #{Time.current.strftime('%H:%M:%S')} erstellt.", at: [ 0, -15 ]) + end + @prawn_document.bounding_box([0, 0], width: 516) do + hr + end + @prawn_document.bounding_box([0, 766], width: 516) do + hr + end + end + x = params p = @pages @prawn_document.outline.define do x.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index| section("#{element_index} #{element.title}") do success_criteria.each.with_index(1) do |sc, sc_index| - page(title: "#{element_index}.#{sc_index} itle}", destination: p[sc.id]) + page(title: "#{element_index}.#{sc_index} #{sc.title}", destination: p[sc.id]) end end end diff --git a/config/initializers/prawn.rb b/config/initializers/prawn.rb index 41bf34b..7754ea7 100644 --- a/config/initializers/prawn.rb +++ b/config/initializers/prawn.rb @@ -2,9 +2,8 @@ PrawnRails.config do |config| config.page_layout = :portrait config.page_size = "A4" config.skip_page_creation = false - config.left_margin = 48 - config.top_margin = 48 - config.right_margin = 48 - config.bottom_margin = 48 + config.left_margin = 32 + config.top_margin = 64 + config.right_margin = 32 + config.bottom_margin = 32 end -