2

我想通过 rghost 在 RoR 上创建条形码 jpg 文件。

当我渲染 RGhost 条形码内容时,出现以下异常...

failed created_jpg_new: private method `readlines' called for nil:NilClass
image file is an unrecognised format

我的编码开始create_jpg(code_word)

def create_jpg(code_word)
  begin
    img = encode(code_word)
  rescue => exc
          Rails.logger.info("failed create_jpg: #{exc}")
     else
           File.open(img_path, "w+b") { |f|
                 f << img
          }
    end
end

def encode(code_word)
    doc = RGhost::Document.new
    doc.barcode_rationalizedCodabar code_word
    return doc.render_stream(:jpg)
end

有什么问题doc.render_stream(:jpg)吗?

4

0 回答 0