2017-05-31 17:39:15 +02:00
|
|
|
require 'prawn/measurement_extensions'
|
|
|
|
|
2019-03-07 00:51:11 +01:00
|
|
|
#----- A4 page size
|
|
|
|
page_size = 'A4'
|
|
|
|
page_height = 842
|
|
|
|
page_width = 595
|
|
|
|
|
|
|
|
#----- margins
|
|
|
|
body_width = 400
|
|
|
|
top_margin = 50
|
|
|
|
bottom_margin = 20
|
|
|
|
footer_height = top_margin - bottom_margin
|
|
|
|
|
|
|
|
right_margin = (page_width - body_width)/2
|
|
|
|
left_margin = right_margin
|
|
|
|
|
|
|
|
#----- size of images
|
|
|
|
max_logo_width = body_width
|
|
|
|
max_logo_height = 50.mm
|
|
|
|
max_signature_size = 50.mm
|
|
|
|
|
|
|
|
prawn_document(margin: [top_margin, right_margin, bottom_margin, left_margin], page_size: page_size) do |pdf|
|
2019-01-30 13:33:31 +01:00
|
|
|
pdf.font_families.update( 'liberation serif' => { normal: Rails.root.join('lib/prawn/fonts/liberation_serif/LiberationSerif-Regular.ttf' )})
|
|
|
|
pdf.font 'liberation serif'
|
2017-05-31 17:39:15 +02:00
|
|
|
|
|
|
|
grey = '555555'
|
|
|
|
black = '333333'
|
|
|
|
|
2019-03-07 00:51:11 +01:00
|
|
|
body_height = pdf.cursor - footer_height
|
|
|
|
|
|
|
|
pdf.bounding_box([0, pdf.cursor], width: body_width, height: body_height) do
|
2017-05-31 17:39:15 +02:00
|
|
|
if @logo.present?
|
2019-08-27 17:42:52 +02:00
|
|
|
logo_file = if @logo.is_a?(ActiveStorage::Attached::One)
|
|
|
|
@logo.download
|
|
|
|
else
|
|
|
|
@logo.read
|
|
|
|
end
|
|
|
|
pdf.image StringIO.new(logo_file), fit: [max_logo_width , max_logo_height], position: :center
|
2017-05-31 17:39:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
pdf.fill_color grey
|
|
|
|
pdf.pad_top(40) { pdf.text "le #{l(@created_at, format: '%e %B %Y')}", size: 10, align: :right, character_spacing: -0.5 }
|
|
|
|
|
|
|
|
pdf.fill_color black
|
|
|
|
pdf.pad_top(40) { pdf.text @title, size: 18, character_spacing: -0.2 }
|
|
|
|
|
|
|
|
pdf.fill_color grey
|
2019-01-23 17:33:22 +01:00
|
|
|
pdf.pad_top(30) { pdf.text @body, size: 10, character_spacing: -0.2, align: :justify }
|
2017-05-31 17:39:15 +02:00
|
|
|
|
|
|
|
if @signature.present?
|
|
|
|
pdf.pad_top(40) do
|
2019-08-27 17:42:52 +02:00
|
|
|
signature_file = if @signature.is_a?(ActiveStorage::Attached::One)
|
|
|
|
@signature.download
|
|
|
|
else
|
|
|
|
@signature.read
|
|
|
|
end
|
|
|
|
pdf.image StringIO.new(signature_file), fit: [max_signature_size , max_signature_size], position: :right
|
2017-05-31 17:39:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
pdf.repeat(:all) do
|
2019-03-07 00:51:11 +01:00
|
|
|
pdf.move_cursor_to footer_height - 10
|
2017-05-31 17:39:15 +02:00
|
|
|
pdf.fill_color grey
|
|
|
|
pdf.text @footer, align: :center, size: 8
|
|
|
|
end
|
|
|
|
end
|