我使用 Prawn 创建 pdf 文件,我想将徽标放入文件中。我查看了此站点创建 pdf以参考如何添加图像。
这是我在ExamResultPdf.rb
文件中生成pdf的代码:
def initialize(exam, view)
super(top_margin: 70)
@exam = exam
exam_number # line 9, I removed codes are not relevant
end
def exam_number
logo_path = "#{Rails.root}/app/assets/images/logo_hoasen.png"
image logo_path, height: 200, width: 200
text "Examination Result \##{@exam.id}", size: 30, style: :bold
end
但是当我转到 page 时/result.pdf
,它有错误:
Prawn::Errors::UnsupportedImageType in ExamsController#result
PNG uses unsupported interlace method
# Trace
app/pdfs/exam_result_pdf.rb:18:in `exam_number'
app/pdfs/exam_result_pdf.rb:9:in `initialize'
app/controllers/exams_controller.rb:43:in `new'
app/controllers/exams_controller.rb:43:in `block (2 levels) in result'
app/controllers/exams_controller.rb:40:in `result'
我的exams_controller
:
def result
@exam = Exam.find(params[:id])
@general_exam = GeneralExam.where(id: @exam.general_exam_id).first
@topic_questions = TopicQuestion.where(general_exam_id: @general_exam.id)
@exam_result = ExamResult.where(exam_id: @exam.id, user_id: @exam.user_id).first
respond_to do |format|
format.html
format.pdf do
pdf = ExamResultPdf.new(@exam, view_context) # line 43
send_data pdf.render, filename: "exam_result_#{@exam.id}",
type: "application/pdf",
disposition: "inline"
end
end
end
所以我想问为什么会出现这个错误,Prawn is not support png file?如何将图像放入pdf文件?
更新
我用过jpg
or jpeg
file,但也没有用。