问题描述
我尝试编写一个简单的程序来将 PDF 文件转换为 JPG。主要思想是一个简单的 .exe 文件,它将在同一目录中找到所有 PDF 文件,并将它们转换为 JPG 后将它们放在新文件夹中。 我做到了!使用 pdf2image,我的程序完全按照我的意愿和 .py 和 .exe 执行。但是,在另一台 PC 上运行此程序后,popper >following Cmd 屏幕截图出现错误 所以,我明白,该程序试图找到一个 popper。并且肯定在另一台 PC 上找不到它。
我试过--hidden-import、--onedir、--onefile 等。 也在这里看到了一些类似的问题,如:
Include poppler while generating an application using pyinstaller
但是,或者我做错了什么,或者在这道题中无法清楚地理解如何做解决方案。
我该怎么办?
#P.S.也许,有更好的库或模块来创建这种程序?
完整代码:
import os
import pdf2image
from pdf2image import convert_from_path
from inspect import getsourcefile
from pdf2image.exceptions import (
PDFInfonotinstalledError,pdfpageCountError,PDFSyntaxError
)
# Create output direction
# Direction of executable file
script_dir = os.path.abspath(getsourcefile(lambda:0))
# print(script_dir)
output_dir = 'JPG'
# List for files which wasn't converted
error_list = []
# If path don't exist - create
if not os.path.exists(output_dir):
os.makedirs(output_dir)
#print('Path has been created',"\n")
else:
pass
#print('Directory exist',"\n")
# Show all files in directory
file_list = os.listdir()
print(file_list,"List of files")
for file in file_list:
try:
# print(file)
pages = convert_from_path(file,dpi=300,fmt='jpg',output_folder=output_dir,output_file=file)
except Exception as e: print(e)
print("File wasn't converted:","\n")
if len(error_list) == 0:
print(0,"\n")
else:
for f in error_list:
print(f)
input("Done! Press Enter")
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)