小编典典
!!! 注意!!!
!!! 这仅适用于PYTHON 2 !!!!
我目前正在为python3更新
viranthas pypdfocr在python 3上无法正常工作。
要在python 2上使用,请愉快地使用以下版本。
终于我找到了可以使用的解决方案。
我使用pypdfocr及其pypdfocr_gs库
pypdfocr.pypdfocr_gs.PyGs({}).make_img_from_pdf(pdf_file)
检索jpg图片,然后使用PIL从中获取ImageTk.PhotoImage实例,并在我的代码中使用它们。
ImageTk.PhotoImage(_img_file_handle)
我将尽快添加适当的示例。
编辑:
正如这里所承诺的那样,代码
import pypdfocr.pypdfocr_gs as pdfImg
from PIL import Image, ImageTk
import Tkinter as tk
import ttk
import glob, os
root=tk.Tk()
__f_tmp=glob.glob(pdfImg.PyGs({}).make_img_from_pdf("\tmp\test.pdf")[1])[0]
# ^ this is needed for a "default"-Config
__img=Image.open(__f_tmp)
__tk_img=ImageTk.PhotoImage(__img)
ttk.Label(root, image=__tk_img).grid()
__img.close()
os.remove(__f_tmp)
root.mainloop()
编辑:
使用viranthas pypdfocr版本似乎在处理Windows 10和pythons子进程内部存在错误:
# extract from pypdfocr_gs:
def _run_gs(self, options, output_filename, pdf_filename):
try:
cmd = '%s -q -dNOPAUSE %s -sOutputFile="%s" "%s" -c quit' % (self.binary, options, output_filename, pdf_filename)
logging.info(cmd)
# Change this line for Windows 10:
# out = subprocess.check_output(cmd, shell=True)
out = subprocess.check_output(cmd)
# end of extract
2020-12-20