简体   繁体   中英

Adding image to PDF in Prawn using image data

So I have an image that's being saved in a database that I need to show on my Prawn Pdf, but when I pull the image, decode it, and try to display it on the Prawn PDF, I keep getting the issue where it wants a file path. Is there a way that I can pass the image data to the pdf, instead of the a file path, and it can just display that image?

Is there a better way?

Prawn can accept a StringIO, with the image data all in memory:

require 'stringio'

image_data = StringIO.new( Base64.decode64(@image) )    
pdf.image(image_data)

好的,我最终找到了如何做到这一点。

pdf.image (MiniMagick::Image.read(Base64.decode64(self.signature))).format('jpg').path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM