增加pdf文件的读取
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""文档解析器命令行交互模块,提供命令行接口。"""
|
||||
"""文档解析器命令行交互模块,提供命令行接口。支持 DOCX、PPTX、XLSX 和 PDF 文件。"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
@@ -7,16 +7,17 @@ import sys
|
||||
|
||||
import common
|
||||
import docx
|
||||
import pdf
|
||||
import pptx
|
||||
import xlsx
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="将 DOCX、PPTX 或 XLSX 文件解析为 Markdown"
|
||||
description="将 DOCX、PPTX、XLSX 或 PDF 文件解析为 Markdown"
|
||||
)
|
||||
|
||||
parser.add_argument("file_path", help="DOCX、PPTX 或 XLSX 文件的绝对路径")
|
||||
parser.add_argument("file_path", help="DOCX、PPTX、XLSX 或 PDF 文件的绝对路径")
|
||||
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
@@ -58,7 +59,7 @@ def main() -> None:
|
||||
|
||||
file_type = common.detect_file_type(args.file_path)
|
||||
if not file_type:
|
||||
print(f"错误: 不是有效的 DOCX、PPTX 或 XLSX 格式: {args.file_path}")
|
||||
print(f"错误: 不是有效的 DOCX、PPTX、XLSX 或 PDF 格式: {args.file_path}")
|
||||
sys.exit(1)
|
||||
|
||||
if file_type == "docx":
|
||||
@@ -73,12 +74,18 @@ def main() -> None:
|
||||
("python-pptx", pptx.parse_pptx_with_python_pptx),
|
||||
("XML 原生解析", pptx.parse_pptx_with_xml),
|
||||
]
|
||||
else:
|
||||
elif file_type == "xlsx":
|
||||
parsers = [
|
||||
("MarkItDown", xlsx.parse_xlsx_with_markitdown),
|
||||
("pandas", xlsx.parse_xlsx_with_pandas),
|
||||
("XML 原生解析", xlsx.parse_xlsx_with_xml),
|
||||
]
|
||||
else:
|
||||
parsers = [
|
||||
("MarkItDown", pdf.parse_pdf_with_markitdown),
|
||||
("unstructured", pdf.parse_pdf_with_unstructured),
|
||||
("pypdf", pdf.parse_pdf_with_pypdf),
|
||||
]
|
||||
|
||||
failures = []
|
||||
content = None
|
||||
|
||||
Reference in New Issue
Block a user