deanmalmgren / textract

extract text from any document. no muss. no fuss.
http://textract.readthedocs.io
MIT License
3.91k stars 602 forks source link

UTF-8 encoded files not properly decoded #203

Open workflowsguy opened 6 years ago

workflowsguy commented 6 years ago

I have a text file encoded in UTF-8 containing

This is a Text with Umlauts: äöüßÄÖÜ

Running print(textract.process(commandlineArguments.filename)) on this file under Python 3 gives

b'This is a Text with Umlauts: \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\xc3\x84\xc3\x96\xc3\x9c'

The same with a pdf file containing umlaut characters.

Adding an encoding='utf-8' parameter has no effect.

ignacy130 commented 5 years ago

Is it related to textract? What when you decode your string? https://stackoverflow.com/a/37016987

workflowsguy commented 5 years ago

Is it related to textract?

Judging from the following code and the output, I'd say "yes"

import textract
text = textract.process('Umlauttest.txt')
print(text)
print('==================')
with open('Umlauttest.txt', 'r') as file:
    text = file.read()
print(text)

b'This is a text with Umlauts: \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\xc3\x84\xc3\x96\xc3\x9c\nDies ist ein Text mit Umlauten: \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\xc3\x84\xc3\x96\xc3\x9c\n'
==================
This is a text with Umlauts: äöüßÄÖÜ
Dies ist ein Text mit Umlauten: äöüßÄÖÜ
jpweytjens commented 5 years ago

@workflowsguy I need to look into this why textract is returning a bytes object and not a str object. In the meanwhile, you can do the following

import textract as txt
text = txt.process("Umlauttest.txt")
text = text.decode("utf8")
filipopo commented 4 years ago

Is this... on hiatus