栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

适用于Python Tkinter的PDF查看器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

适用于Python Tkinter的PDF查看器

!!! 注意!!!
!!! 这仅适用于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("tmptest.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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/667954.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号