Improve pdf
This commit is contained in:
parent
89ef15f41d
commit
4abae91a5a
3 changed files with 59 additions and 9 deletions
|
|
@ -71,7 +71,6 @@ module PdfDocuments
|
||||||
|
|
||||||
def logo
|
def logo
|
||||||
@prawn_document.image "app/assets/images/logo-apfelschule.png", width: 150
|
@prawn_document.image "app/assets/images/logo-apfelschule.png", width: 150
|
||||||
@prawn_document.move_down 30
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_rich_text(rich_text)
|
def prepare_rich_text(rich_text)
|
||||||
|
|
@ -112,7 +111,11 @@ module PdfDocuments
|
||||||
end
|
end
|
||||||
|
|
||||||
def image(attachable, **args)
|
def image(attachable, **args)
|
||||||
@prawn_document.image(ActiveStorage::Blob.service.path_for(attachable.key), **args) rescue StandardError do false end
|
begin
|
||||||
|
@prawn_document.image(ActiveStorage::Blob.service.path_for(attachable.key), **args) && raise("david")
|
||||||
|
rescue StandardError
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_page_break(&block)
|
def without_page_break(&block)
|
||||||
|
|
@ -140,8 +143,8 @@ module PdfDocuments
|
||||||
@prawn_document.text("absolute right: #{Float(@prawn_document.bounds.absolute_right).round(2)}")
|
@prawn_document.text("absolute right: #{Float(@prawn_document.bounds.absolute_right).round(2)}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_page
|
def new_page(required_space: 0)
|
||||||
@prawn_document.start_new_page
|
@prawn_document.start_new_page if @prawn_document.cursor <= required_space + 10
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,31 @@ module PdfDocuments
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate
|
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
|
logo
|
||||||
@prawn_document.formatted_text_box [ {
|
move_down 20
|
||||||
text: "Dieses Dokument wurd am #{Time.current.strftime('%d %B %Y')} um #{Time.current.strftime('%H:%M:%S')} erstellt.", size: 8, align: :right
|
|
||||||
} ], align: :right
|
|
||||||
|
|
||||||
heading1 params.report.name
|
heading1 params.report.name
|
||||||
rich_text params.report.comment
|
rich_text params.report.comment
|
||||||
|
@pages = {}
|
||||||
|
|
||||||
params.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
|
params.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
|
||||||
new_page if element_index > 1
|
new_page(required_space: 200) if element_index > 1
|
||||||
without_page_break do
|
without_page_break do
|
||||||
heading2 "#{element_index} #{element.title}"
|
heading2 "#{element_index} #{element.title}"
|
||||||
bold("#{element.page.path}")
|
bold("#{element.page.path}")
|
||||||
|
|
@ -24,9 +39,31 @@ module PdfDocuments
|
||||||
move_down(10)
|
move_down(10)
|
||||||
|
|
||||||
success_criteria.each.with_index(1) do |success_criterion, sc_index|
|
success_criteria.each.with_index(1) do |success_criterion, sc_index|
|
||||||
|
@pages[success_criterion.id] = @prawn_document.page_number
|
||||||
success_criterion_row(success_criterion, [ element_index, sc_index ])
|
success_criterion_row(success_criterion, [ element_index, sc_index ])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
string = "Seite <page> / <total>"
|
||||||
|
# Green page numbers 1 to 7
|
||||||
|
options = {
|
||||||
|
at: [ @prawn_document.bounds.right - 150, -10 ],
|
||||||
|
width: 150,
|
||||||
|
align: :right,
|
||||||
|
start_count_at: 1
|
||||||
|
}
|
||||||
|
@prawn_document.number_pages string, options
|
||||||
|
|
||||||
|
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])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
10
config/initializers/prawn.rb
Normal file
10
config/initializers/prawn.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue