我用蝦創建PDF文件,我想把徽標放在文件中。我已經看過這個網站Creating pdf來引用如何添加圖像。添加圖像使用蝦,得到錯誤:蝦:::錯誤:: UnsupportedImageType,PNG使用不受支持的交錯方法
這是我在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
但是當我去/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
所以我想問問爲什麼我得到這個錯誤,蝦不支持rt png文件?我怎樣才能把圖像放在pdf文件中?
更新
我用jpg
或jpeg
文件,但它沒有工作過。