I tried to convert pdf document to txt file. (example of pdf file link)
So I tried like below.
But the extracted text is strange like ??챘#?遏?h첨챦_철?‾n?~w??¬?k
How can I fix it?
#!/usr/bin/python
# -*- coding: cp949 -*-
# -*- coding: utf-8 -*-
# -*- coding: latin-1 -*-
# -*- coding: euc-kr -*-
import codecs
import pyPdf
filename = "d:/data/processed_data/paper/iscram/2006/iscram1.pdf"
#pdf = codecs.open(filename, "rb", encoding = 'utf-8')
pdf = codecs.open(filename, "rb", encoding = 'latin1')
for page in pdf:
print page.encode('utf-8')
I use a win7-64bit korean version.
I tried it to another way by using pyPdf like below
import os
import glob
from pyPdf import PdfFileReader
import pdfminer
f=open("d:/data/processed_data/paper/iscram/2006/iscram1.txt",'w')
parent = "d:/data/processed_data/paper/iscram/2006"
os.chdir(parent)
filename = os.path.abspath('iscram1.pdf')
input = PdfFileReader(file(filename, "rb"))
for page in input.pages:
f.write(page.extractText())
but it doesn't work and it occurs ''ascii' codec can't encode character u'\u0152' in position 602: ordinal not in range(128)' error