加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用Prawn添加图像,得到错误:Prawn :: Errors

发布时间:2020-12-17 01:26:33 所属栏目:百科 来源:网络整理
导读:我用Prawn创建了pdf文件,我想将徽标放在文件中.我已经看过这个网站 Creating pdf,以参考如何添加图像. 这是我在ExamResultPdf.rb文件中生成pdf的代码: def initialize(exam,view) super(top_margin: 70) @exam = exam exam_number # line 9,I removed codes
我用Prawn创建了pdf文件,我想将徽标放在文件中.我已经看过这个网站 Creating 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

但是当我去页面/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'

我的考试控制器:

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不支持png文件?如何将图像放入pdf文件?

更新

我使用过jpg或jpeg文件,但它也没有用.

解决方法

有许多类型的PNG – 绝大多数都会与虾一起工作,但有些不会.

最简单的选择是将其转换为JPG或将其重新保存为非隔行扫描的PNG.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读