2.17 增加读文件pdf接口测试1
This commit is contained in:
parent
3d003a5631
commit
24542b47d2
@ -79,10 +79,9 @@ def read_pdf_main(pdf_path):
|
||||
# common_header=extract_common_header(pdf_path)
|
||||
common_header=""
|
||||
try:
|
||||
with open(pdf_path, "rb") as f:
|
||||
pdf_document = PdfReader(f)
|
||||
total_pages = len(pdf_document.pages)
|
||||
get_text = create_get_text_function('pypdf2', pdf_document)
|
||||
with fitz.open(pdf_path) as pdf_document:
|
||||
total_pages = pdf_document.page_count
|
||||
get_text = create_get_text_function('fitz', pdf_document)
|
||||
start_page, end_page = process_pages(get_text, common_header,total_pages)
|
||||
return start_page, end_page
|
||||
except Exception as e_pypdf2:
|
||||
@ -90,9 +89,10 @@ def read_pdf_main(pdf_path):
|
||||
|
||||
# 如果 PyPDF2 失败,尝试使用 PyMuPDF
|
||||
try:
|
||||
with fitz.open(pdf_path) as pdf_document:
|
||||
total_pages = pdf_document.page_count
|
||||
get_text = create_get_text_function('fitz', pdf_document)
|
||||
with open(pdf_path, "rb") as f:
|
||||
pdf_document = PdfReader(f)
|
||||
total_pages = len(pdf_document.pages)
|
||||
get_text = create_get_text_function('pypdf2', pdf_document)
|
||||
start_page, end_page = process_pages(get_text, common_header,total_pages)
|
||||
return start_page, end_page
|
||||
except Exception as e_pypdf2:
|
||||
|
@ -45,7 +45,6 @@ def create_app():
|
||||
for handler in logger.handlers[:]:
|
||||
handler.close()
|
||||
logger.removeHandler(handler)
|
||||
gc.collect()
|
||||
return app
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user