Decoding binary to pdf

后端 未结 1 1389
花落未央
花落未央 2021-01-16 17:16

I\'m using a platform that, when you upload pdf\'s to it, converts the pdf with the base64 encode in Python. Then it stores the binary string in the database.

Now I

相关标签:
1条回答
  • 2021-01-16 17:42

    base64.decode(,) takes files as args. you want to try

    fout.write(base64.decodestring(code))
    

    though your code example is not encoded. Here's a working example:

    #!/usr/bin/python
    import base64, os
    code = 'TXkgYmluYXJ5IHN0cmluZw==\n'
    with open(os.path.expanduser('~/Desktop/test.pdf'), 'wb') as fout:
         fout.write(base64.decodestring(code))
    
    0 讨论(0)
提交回复
热议问题