MyNameIsntBob
MyNameIsntBob

Reputation: 47

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?

Upvotes: 1

Views: 781

Answers (2)

James Healy
James Healy

Reputation: 15168

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)

Upvotes: 1

MyNameIsntBob
MyNameIsntBob

Reputation: 47

Ok, I ended up finding out how to do that.

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

Upvotes: 0

Related Questions