【问题标题】:What is the best way to convert a pdf file into base64Binary?将 pdf 文件转换为 base64Binary 的最佳方法是什么?
【发布时间】:2017-08-22 09:02:58
【问题描述】:

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

我的逻辑(不是 python)将文件的内容读入字节数组,然后使用类似Convert.ToBase64String() method 的东西来获取Base64 string

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

请告诉我在 python 中convert a pdf file into base64Binary 的正确方法是什么

【问题讨论】:

  • 这不是 Python
  • 我已经编辑了我的帖子。如果还有什么不清楚的地方请告诉我

标签: python python-2.7 python-3.x pdf ipython


【解决方案1】:

就这么简单

import base64

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

来源:Encoding an image file with base64

【讨论】:

    猜你喜欢
    • 2012-02-29
    • 2010-09-21
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 2010-09-09
    相关资源
    最近更新 更多