【发布时间】:2018-01-04 21:50:51
【问题描述】:
我有一个 PDF 作为 base64 字符串,我需要使用 Python 将其写入文件。 我试过这个:
import base64
base64String = "data:application/pdf;base64,JVBERi0xLjQKJeHp69MKMSAwIG9iago8PC9Qcm9kdWNlciAoU2tpYS9..."
with open('temp.pdf', 'wb') as theFile:
theFile.write(base64.b64decode(base64String))
但它没有创建有效的 PDF 文件。 我错过了什么?
【问题讨论】:
-
你能告诉我你在这方面做了什么改变,因为我对那种类型的字符串也有同样的问题。
-
我必须得到结果但不正确。你得到 pdf 的正确结果了吗?
标签: python pdf base64 file-writing