pdf提取排序
This commit is contained in:
@@ -37,13 +37,18 @@ async def _parse_txt(content: bytes) -> str:
|
|||||||
|
|
||||||
|
|
||||||
async def _parse_pdf(content: bytes) -> str:
|
async def _parse_pdf(content: bytes) -> str:
|
||||||
"""解析 PDF:使用 PyMuPDF 逐页 get_text() 拼接为全文文本"""
|
"""解析 PDF:使用 PyMuPDF 逐页 get_text() 拼接为全文文本
|
||||||
|
|
||||||
|
sort=True 按文本块坐标(y,x)排序输出,即视觉阅读顺序。
|
||||||
|
默认的内容流顺序对模板生成的简历完全不可用:这类简历的「公司/职位/时间」表头是绝对定位文本框,
|
||||||
|
会被整批甩到全文最前面,与各自的职责描述相隔几十行,AI 无法还原归属关系。
|
||||||
|
"""
|
||||||
|
|
||||||
def _extract() -> str:
|
def _extract() -> str:
|
||||||
parts: list[str] = []
|
parts: list[str] = []
|
||||||
with fitz.open(stream=content, filetype="pdf") as doc:
|
with fitz.open(stream=content, filetype="pdf") as doc:
|
||||||
for page in doc:
|
for page in doc:
|
||||||
parts.append(page.get_text())
|
parts.append(page.get_text("text", sort=True))
|
||||||
return "\n".join(parts)
|
return "\n".join(parts)
|
||||||
|
|
||||||
return await asyncio.to_thread(_extract)
|
return await asyncio.to_thread(_extract)
|
||||||
|
|||||||
Reference in New Issue
Block a user