Base64 Image in String

Showing 1-2 of 2 messages
Base64 Image in String Mac 11/23/10 1:25 PM
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

I'm getting a not found error.

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

Thanks in advance!

Re: Base64 Image in String Bill Kirtley 11/24/10 6:33 AM
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 ='image')
  file.write ActiveSupport::Base64.decode64(image)

  image file.path