Refactored pdf generation with newest prawn.
This commit is contained in:
parent
78cc423a46
commit
eb532babd6
31 changed files with 311 additions and 2118 deletions
32
lib/order_pdf.rb
Normal file
32
lib/order_pdf.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
require "prawn/measurement_extensions"
|
||||
|
||||
class OrderPdf < Prawn::Document
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
def initialize(order, options = {})
|
||||
options[:page_size] ||= "A4"
|
||||
#options[:left_margin] ||= 40
|
||||
#options[:right_margin] ||= 40
|
||||
options[:top_margin] ||= 50
|
||||
#options[:bottom_margin] ||= 40
|
||||
super(options)
|
||||
@order = order
|
||||
end
|
||||
|
||||
def to_pdf
|
||||
# Define header
|
||||
repeat :all, dynamic: true do
|
||||
draw_text title, size: 10, style: :bold, at: [bounds.left, bounds.top+20] if title # Header
|
||||
draw_text "Seite #{page_number}", size: 8, at: [bounds.left, bounds.bottom-10] # Footer
|
||||
end
|
||||
|
||||
body # Add content, which is defined in subclasses
|
||||
|
||||
render # Render pdf
|
||||
end
|
||||
|
||||
# Helper method to test pdf via rails console: OrderByGroups.new(order).save_tmp
|
||||
def save_tmp
|
||||
File.open("#{Rails.root}/tmp/#{self.class.to_s.underscore}.pdf", 'w') {|f| f.write(to_pdf.force_encoding("UTF-8")) }
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue