我正在尝试从unicode编码的pdf文件中提取sinhala文本。 但文字没有正确提取
PDF中的文字是: කවුරුහරිඔබෙන්ඇහුවොත්
提取的文字是: කවුරුහරිඔබෙන්ඇහුබොත්
一封信被另一封信取代。 这是我正在使用的代码。
import io
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
def convert_pdf_to_txt(path):
rsrcmgr = PDFResourceManager()
retstr = io.StringIO()
codec = 'utf-8'
laparams = LAParams()
device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
fp = open(path, 'rb')
interpreter = PDFPageInterpreter(rsrcmgr, device)
caching = True
pagenos = set()
for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password, caching=caching, check_extractable=True):
interpreter.process_page(page)
text = retstr.getvalue()
fp.close()
device.close()
retstr.close()
return text
u = convert_pdf_to_txt('sinhala.pdf')
print(u)