Need Base64 representation of Prawn Output

47 views
Skip to first unread message

Harry Whitehouse

unread,
Aug 20, 2016, 2:54:04 AM8/20/16
to Prawn
Hi There!

I realize I can #render_file to create my output as a PDF file, but I'm wondering if there is a way I can convert the PDF to a BASE64 representation directly in my Ruby code? 

An obvious way would be to write the file, then read it again as binary data and convert to BASE64 that way. 

But is there a way I can convert the PDF object as BASE64 directly without creating a PDF file?

Many thanks...

Harry

Alexander Mankuta

unread,
Aug 20, 2016, 3:10:38 AM8/20/16
to Prawn
Hi Harry,

You can use render method to get a string without writing a file. Then you can use Base64.encode from stdlib to get a base64 encoded string.

--
Regards,
Alex

Harry Whitehouse

unread,
Aug 23, 2016, 1:34:40 PM8/23/16
to Prawn
Thank you Alex!!!!!!  Worked just great!
Reply all
Reply to author
Forward
0 new messages