class Report
attr_reader :pdf
def to_pdf
Prawn::Document.new(page_layout: page_layout) do |pdf|
@pdf = pdf
pdf.repeat(:all) do
frame_page
end
pdf.repeat(:all) do
write_header
end
#write_section_divider
puts "wrote the header" #this is not getting hit
write_body
In my subclass:
def write_header
puts "Writing header"
pdf.move_down 8
pdf.text title, size: 22, style: :bold, align: :center
puts "wrote title"
pdf.bounding_box([0, pdf.cursor], width: pdf.bounds.right, height: 28) do
puts "bounding box"
pdf.move_down 8
pdf.text date_title, size: 16, align: :center
pdf.text current_day_title, size: 16, align: :center
puts "moved down"
end
puts "exited bounding box"
end
F, [2015-02-23T02:18:30.106303 #6] FATAL -- :
2015-02-23T02:18:30.106684+00:00 app[web.1]: app/reports/report.rb:6:in `to_pdf'
2015-02-23T02:18:30.106680+00:00 app[web.1]: app/reports/report.rb:13:in `block in to_pdf'
2015-02-23T02:18:30.106682+00:00 app[web.1]: app/reports/report.rb:6:in `new'
2015-02-23T02:18:30.106674+00:00 app[web.1]: Prawn::Errors::EmptyGraphicStateStack (
2015-02-23T02:18:30.106677+00:00 app[web.1]: You have reached the end of the graphic state stack):
2015-02-23T02:18:30.106690+00:00 app[web.1]:
2015-02-23T02:18:30.106691+00:00 app[web.1]:
2015-02-23T02:18:30.106688+00:00 app[web.1]: app/controllers/verified_return_money_reports_controller.rb:21:in `create'
2015-02-23T02:18:30.106687+00:00 app[web.1]: app/reports/verified_return_money_report.rb:6:in `to_pdf'
Why is my Prawn drawing failing?
You have a repeater which is applied to every page, and whose content is more than one page wide. That's what Prawn is telling you with that not very self-explaining error.
Now, from the stacktrace the error comes from write_header
call. It seems your bounding box on that method has a fixed height (28
) and it's content is higher: two lines and the move down 8
.
Try extending bounding_box's height or making it's content shorter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With