Skip to content

Instantly share code, notes, and snippets.

@ismarsantos
Forked from lappi-lynx/prawn_io_image.rb
Created May 23, 2018 01:50
Show Gist options
  • Save ismarsantos/0f7069fb7e3947f563a2dab5b6b1092e to your computer and use it in GitHub Desktop.
Save ismarsantos/0f7069fb7e3947f563a2dab5b6b1092e to your computer and use it in GitHub Desktop.
Prawn PDF images with Base64 and StringIO
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment