-
-
Save ismarsantos/0f7069fb7e3947f563a2dab5b6b1092e to your computer and use it in GitHub Desktop.
Prawn PDF images with Base64 and StringIO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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