1

Im trying to convert a Base64 Docx to a Base64 pdf, for test purpose im receiving the base64 docx and im saving it in my Django static folder like this:

Proyect
--App
----static
------Docs
--------test.docx

So, Im trying with doxc2pdf library to make the convertion and the into base64 like this:

class Converttest(View):

    def post(self, request, *args, **kwargs):
        template = loader.get_template('home.html')

        testdoc = static('Docs/test.docx')
        pdf = convert(testdoc)
        encoded = base64.b64encode(pdf)
        context = {}
        return HttpResponse(template.render(context, request))

But im getting this error:

pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
> g:\python_projects\reps\stratos\strategy\views.py(162)post()
-> convert(testdoc)

Any idea what am I doing wrong ?

jsanchezs
  • 1,992
  • 3
  • 25
  • 51

1 Answers1

0
sample_string = "test string"
sample_string_bytes = sample_string.encode("ascii")
  
base64_bytes = base64.b64encode(sample_string_bytes)
base64_string = base64_bytes.decode("ascii")
saro
  • 705
  • 3
  • 13