Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Prawn reached end of graphics state stack

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?

like image 924
quantumpotato Avatar asked Feb 23 '15 02:02

quantumpotato


1 Answers

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.

like image 118
dgilperez Avatar answered Oct 21 '22 16:10

dgilperez