Base64 Image in String

412 views
Skip to first unread message

Mac

unread,
Nov 23, 2010, 4:25:53 PM11/23/10
to Prawn
I would like to embed an image (that is stored as a base64 blob in a
database) in a pdf.

I have tried the following from irb:

Note: "test" is the base64 string and I have manually set it's value

require 'prawn'
Prawn::Document.generate('test.pdf') do
image test
end


I'm getting a not found error.

Is this the correct way to do this? Or am I missing something?

Thanks in advance!


Bill Kirtley

unread,
Nov 24, 2010, 9:33:15 AM11/24/10
to prawn...@googlegroups.com
Prawn wants a file path rather than encoded image data. You could use a tempfile:

require 'prawn'
require 'tempfile'
require 'active_support' # for base64

Prawn::Document.generate('/tmp/test.pdf') do
file = Tempfile.new('image')
file.write ActiveSupport::Base64.decode64(image)
file.close

image file.path
end

Reply all
Reply to author
Forward
0 new messages