【问题标题】:Debugging Prawn reached end of graphics state stack调试虾到达图形状态堆栈的末尾
【发布时间】:2015-02-23 02:21:15
【问题描述】:
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

在我的子类中:

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'

为什么我的 Prawn 绘图失败了?

【问题讨论】:

  • 有什么消息吗?我的回答有帮助吗?

标签: ruby-on-rails prawn


【解决方案1】:

您有一个应用于每一页的转发器,其内容的宽度超过一页。这就是 Prawn 告诉你的那个不是很容易解释的错误。

现在,从堆栈跟踪中,错误来自write_header 调用。看来您在该方法上的边界框具有固定高度(28),并且它的内容更高:两行和move down 8

尝试扩展 bounding_box 的高度或使其内容更短。

【讨论】:

  • 就是这样,高度不足以容纳内容。
  • 即使在确认图像正确后,我仍然遇到此问题。我能够解决它的唯一方法是将repeat(:all) 替换为page_count.times do |i|go_to_page(i+1)
猜你喜欢
  • 2015-08-30
  • 1970-01-01
  • 2022-07-29
  • 2011-07-18
  • 2010-11-13
  • 2017-12-10
  • 2017-04-09
  • 2011-12-08
  • 2018-08-06
相关资源
最近更新 更多