Merge pull request #65 from xerrors/61-bugtext-type-pdf
修复部分文档被识别为Text-lilke PDF 而导致没有触发OCR识别的问题
This commit is contained in:
commit
568d859826
@ -6,12 +6,21 @@ from src.utils.logging_config import logger
|
|||||||
def is_text_pdf(pdf_path):
|
def is_text_pdf(pdf_path):
|
||||||
import fitz
|
import fitz
|
||||||
doc = fitz.open(pdf_path)
|
doc = fitz.open(pdf_path)
|
||||||
for page_num in range(len(doc)):
|
total_pages = len(doc)
|
||||||
|
if total_pages == 0:
|
||||||
|
return False
|
||||||
|
|
||||||
|
text_pages = 0
|
||||||
|
for page_num in range(total_pages):
|
||||||
page = doc.load_page(page_num)
|
page = doc.load_page(page_num)
|
||||||
text = page.get_text()
|
text = page.get_text()
|
||||||
if text.strip(): # 检查是否有文本内容
|
if text.strip(): # 检查是否有文本内容
|
||||||
return True
|
text_pages += 1
|
||||||
return False
|
|
||||||
|
# 计算有文本内容的页面比例
|
||||||
|
text_ratio = text_pages / total_pages
|
||||||
|
# 如果超过50%的页面有文本内容,则认为是文本PDF
|
||||||
|
return text_ratio > 0.5
|
||||||
|
|
||||||
def hashstr(input_string, length=8, with_salt=False):
|
def hashstr(input_string, length=8, with_salt=False):
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user