关于python:将pdf文件转换为base64Binary的最佳方法是什么?

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

使用python,我要convert a pdf file into base64Binary

我的逻辑(不是python)正在将文件的内容读取到字节数组中,然后使用类似Convert.ToBase64String() method的方法来获取Base64 string

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

请让我知道python中convert a pdf file into base64Binary的正确方法是什么


如此简单

1
2
3
4
import base64

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

来源:使用base64编码图像文件