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
|
||||
@prawn_document.image "app/assets/images/logo-apfelschule.png", width: 150
|
||||
@prawn_document.move_down 30
|
||||
end
|
||||
|
||||
def prepare_rich_text(rich_text)
|
||||
|
|
@ -112,7 +111,11 @@ module PdfDocuments
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def without_page_break(&block)
|
||||
|
|
@ -140,8 +143,8 @@ module PdfDocuments
|
|||
@prawn_document.text("absolute right: #{Float(@prawn_document.bounds.absolute_right).round(2)}")
|
||||
end
|
||||
|
||||
def new_page
|
||||
@prawn_document.start_new_page
|
||||
def new_page(required_space: 0)
|
||||
@prawn_document.start_new_page if @prawn_document.cursor <= required_space + 10
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,16 +5,31 @@ 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
|
||||
@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
|
||||
} ], align: :right
|
||||
|
||||
move_down 20
|
||||
heading1 params.report.name
|
||||
rich_text params.report.comment
|
||||
@pages = {}
|
||||
|
||||
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
|
||||
heading2 "#{element_index} #{element.title}"
|
||||
bold("#{element.page.path}")
|
||||
|
|
@ -24,9 +39,31 @@ module PdfDocuments
|
|||
move_down(10)
|
||||
|
||||
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 ])
|
||||
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
|
||||
|
||||
private
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue