Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to convert a pdf file into base64Binary?

Using python, I want to convert a pdf file into base64Binary

My logic(not python) is reading the contents of the file into a byte array and then use something like Convert.ToBase64String() method to get the Base64 string:

byte[] pdfBytes = File.ReadAllBytes(pdfPath);
string pdfBase64 = Convert.ToBase64String(pdfBytes);

Please let me know what is the right approach to convert a pdf file into base64Binary in python

like image 544
me24hour Avatar asked Mar 29 '17 03:03

me24hour


1 Answers

its easy as this

import base64

with open("book.pdf", "rb") as pdf_file:
    encoded_string = base64.b64encode(pdf_file.read())

source: Encoding an image file with base64

like image 126
evexoio Avatar answered Oct 23 '22 17:10

evexoio