【发布时间】:2016-12-28 14:32:37
【问题描述】:
我正在创建一个 pdf 报告,以便使用“squid”gem 显示一些数据。这将允许我在我的 pdf 中显示图表。 我发现的唯一问题是,当图表不适合页面底部时,它看起来部分呈现,看起来一点也不好看。知道如何解决这个问题吗?
这是我用来渲染图表的代码
require 'squid'
class SurveyPdf < Prawn::Document
def initialize(survey, view)
super()
font "#{Rails.root}/app/assets/fonts/roboto-condensed.ttf"
@survey = survey
@view = view
questions
end
def questions
@survey.questions.each do |question|
text "#{question.title}", size: 20
text "Answers #{question.answers.size}", size: 15
if ["single", "select"].include? question.question_type.prefix
if question.answers.choice_counter.any?
chart choices: question.answers.choice_counter
end
end
if question.question_type.prefix == "image"
if question.answers.image_counter.any?
chart images: question.answers.image_counter
end
end
if question.question_type.prefix == "multiple"
if question.answers.multiple_choice_counter.any?
chart choices: question.answers.multiple_choice_counter
end
end
if question.question_type.prefix == "raiting"
move_down 5
if question.answers.any?
text_box "Average rating", size: 12, width: 120, :at => [0, cursor - 2]
text_box "#{average_rating(question.answers.rating_average)}", size: 12, width: 120, :at => [4 * 30, cursor - 2]
else
text_box "Average rating", size: 12, width: 120, :at => [0, cursor - 2]
text_box "0", size: 12, width: 120, :at => [4 * 30, cursor - 2]
end
end
end
end
end
【问题讨论】:
-
解决方案我将使用它来确定图表是否适合剩余空间,如果不能,则添加页面并在那里呈现。例如当前光标位置+图表高度>页面底部
-
什么是页面底部?如果可能的话,你能给我一些代码吗?
-
我添加了一个“答案”来回答您的评论而不是您的问题,但它应该对两者都有帮助
标签: ruby-on-rails ruby prawn