Paste image into prawn pdf with StringIO and base-64 encoding

I getting BASE64_IMAGE_GOES_HERE from signature_pad js lib with getSignatureImage() method.

  def render
    pdf = Prawn::Document
    pdf.image StringIO.new(Base64.decode64(splitBase64(BASE64_IMAGE_GOES_HERE)[:data])), at: [10, cursor - 50], width: 200, height: 125
  end

  def splitBase64(uri)
    if uri.match(%r{^data:(.*?);(.*?),(.*)$})
      return {
        type:      $1, # "image/png"
        encoder:   $2, # "base64"
        data:      $3, # data string
        extension: $1.split('/')[1] # "png"
        }
    end
  end

Поделиться с друзьями

Френдинг

 

Comments

No comments so far.

Leave a Reply

 
(will not be published)
 
 
Comment