commit
5193ad656b
@ -16,9 +16,7 @@ if not os.path.exists(output_folder_path):
|
|||||||
def get_pdf_files_in_directory(directory_path):
|
def get_pdf_files_in_directory(directory_path):
|
||||||
# 确保路径存在
|
# 确保路径存在
|
||||||
if os.path.exists(directory_path) and os.path.isdir(directory_path):
|
if os.path.exists(directory_path) and os.path.isdir(directory_path):
|
||||||
# 使用glob模块搜索所有PDF文件
|
return glob.glob(os.path.join(directory_path, '**', '*.pdf'), recursive=True)
|
||||||
pdf_files = glob.glob(os.path.join(directory_path, '**', '*.pdf'), recursive=True)
|
|
||||||
return pdf_files
|
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
def ocr_pdf_folder(folder_path):
|
def ocr_pdf_folder(folder_path):
|
||||||
@ -41,12 +39,12 @@ def ocr_pdf_folder(folder_path):
|
|||||||
res = result[idx]
|
res = result[idx]
|
||||||
for line in res:
|
for line in res:
|
||||||
# print(line[1][0])
|
# print(line[1][0])
|
||||||
ocr_result = ocr_result + " " + str(line[1][0])
|
ocr_result = f"{ocr_result} {str(line[1][0])}"
|
||||||
|
|
||||||
filename = os.path.splitext(os.path.basename(pdf_path))[0]
|
filename = os.path.splitext(os.path.basename(pdf_path))[0]
|
||||||
|
|
||||||
# 构建TXT文件的完整路径
|
# 构建TXT文件的完整路径
|
||||||
txt_path = os.path.join('res/', filename + '.txt')
|
txt_path = os.path.join('res/', f'{filename}.txt')
|
||||||
|
|
||||||
# 将提取的文本写入TXT文件
|
# 将提取的文本写入TXT文件
|
||||||
with open(txt_path, 'w', encoding='utf-8') as txt_file:
|
with open(txt_path, 'w', encoding='utf-8') as txt_file:
|
Loading…
Reference in New Issue
Block a user