feat: metagpt-Python-PDF-Feedback-UI-20260326
This commit is contained in:
15
resources/competitive_analysis/20260326175651.mmd
Normal file
15
resources/competitive_analysis/20260326175651.mmd
Normal file
@@ -0,0 +1,15 @@
|
||||
quadrantChart
|
||||
title "PDF处理库的易用性与功能性对比"
|
||||
x-axis "低易用性" --> "高易用性"
|
||||
y-axis "低功能性" --> "高功能性"
|
||||
quadrant-1 "首选方案"
|
||||
quadrant-2 "功能强但复杂"
|
||||
quadrant-3 "不推荐"
|
||||
quadrant-4 "简单但功能有限"
|
||||
"PyPDF2": [0.55, 0.35]
|
||||
"pdfplumber": [0.45, 0.75]
|
||||
"pdfminer.six": [0.25, 0.70]
|
||||
"pymupdf": [0.60, 0.85]
|
||||
"pikepdf": [0.40, 0.65]
|
||||
"pypdf": [0.70, 0.50]
|
||||
"目标方案": [0.80, 0.45]
|
||||
19
resources/data_api_design/20260326175651.mmd
Normal file
19
resources/data_api_design/20260326175651.mmd
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
classDiagram
|
||||
class PDFOpener {
|
||||
-str file_path
|
||||
-int start_page
|
||||
-int end_page
|
||||
+__init__(file_path: str, start_page: int, end_page: int)
|
||||
+open() PdfReader
|
||||
+get_info(reader: PdfReader) dict
|
||||
+extract_text(reader: PdfReader) list[str]
|
||||
+display_info(info: dict) None
|
||||
+display_text(texts: list[str]) None
|
||||
+run() None
|
||||
}
|
||||
class Main {
|
||||
+parse_args() argparse.Namespace
|
||||
+main() None
|
||||
}
|
||||
Main --> PDFOpener : creates and uses
|
||||
76
resources/prd/20260326175651.md
Normal file
76
resources/prd/20260326175651.md
Normal file
@@ -0,0 +1,76 @@
|
||||
## Language
|
||||
|
||||
zh_cn
|
||||
|
||||
## Programming Language
|
||||
|
||||
Python
|
||||
|
||||
## Original Requirements
|
||||
|
||||
一个Python程序打开PDF文件,不需要UI,尽量简单
|
||||
|
||||
## Project Name
|
||||
|
||||
pdf_opener
|
||||
|
||||
## Product Goals
|
||||
|
||||
- 实现简单高效地打开和读取PDF文件
|
||||
- 保持代码简洁,无需任何UI界面
|
||||
- 提供基本的PDF内容提取功能
|
||||
|
||||
## User Stories
|
||||
|
||||
- 作为用户,我希望能够通过命令行指定PDF文件路径并打开它
|
||||
- 作为用户,我希望能够提取PDF文件中的文本内容
|
||||
- 作为用户,我希望程序能够处理文件不存在或格式错误的异常情况
|
||||
- 作为用户,我希望能够查看PDF的基本信息,如页数等
|
||||
|
||||
## Competitive Analysis
|
||||
|
||||
- PyPDF2: 纯Python实现,支持PDF读取和基本操作,但对复杂PDF支持有限
|
||||
- pdfplumber: 功能强大,支持文本和表格提取,但依赖较多
|
||||
- pdfminer.six: 文本提取精准,但API较复杂
|
||||
- pymupdf (fitz): 性能优秀,功能全面,但库体积较大
|
||||
- pikepdf: 基于QPDF,支持PDF读写,功能较全面
|
||||
- pypdf: PyPDF2的继任者,持续维护,API简洁
|
||||
|
||||
## Competitive Quadrant Chart
|
||||
|
||||
quadrantChart
|
||||
title "PDF处理库的易用性与功能性对比"
|
||||
x-axis "低易用性" --> "高易用性"
|
||||
y-axis "低功能性" --> "高功能性"
|
||||
quadrant-1 "首选方案"
|
||||
quadrant-2 "功能强但复杂"
|
||||
quadrant-3 "不推荐"
|
||||
quadrant-4 "简单但功能有限"
|
||||
"PyPDF2": [0.55, 0.35]
|
||||
"pdfplumber": [0.45, 0.75]
|
||||
"pdfminer.six": [0.25, 0.70]
|
||||
"pymupdf": [0.60, 0.85]
|
||||
"pikepdf": [0.40, 0.65]
|
||||
"pypdf": [0.70, 0.50]
|
||||
"目标方案": [0.80, 0.45]
|
||||
|
||||
## Requirement Analysis
|
||||
|
||||
该项目需求非常简洁明确:使用Python实现一个能够打开PDF文件的程序,无需任何图形界面(UI),以命令行方式运行。核心功能包括:接受PDF文件路径作为输入参数,打开并读取PDF文件内容,提取文本信息并输出到控制台,同时处理常见异常(如文件不存在、非PDF格式等)。推荐使用pypdf或PyPDF2库,因其安装简单、API直观,完全满足"尽量简单"的要求。
|
||||
|
||||
## Requirement Pool
|
||||
|
||||
- ['P0', '实现通过命令行参数接收PDF文件路径并打开文件']
|
||||
- ['P0', '使用第三方库(如pypdf)读取PDF文件内容并提取文本']
|
||||
- ['P1', '输出PDF基本信息,如总页数、每页文本内容']
|
||||
- ['P1', '处理异常情况:文件不存在、文件格式错误、权限不足等']
|
||||
- ['P2', '支持指定页码范围进行内容提取']
|
||||
|
||||
## UI Design draft
|
||||
|
||||
无UI界面。程序通过命令行运行,格式为:python pdf_opener.py <pdf文件路径>。输出结果直接打印到终端,包括PDF页数信息及各页提取的文本内容。
|
||||
|
||||
## Anything UNCLEAR
|
||||
|
||||
目前需求较为清晰。唯一待确认的是:程序是否只需打开并显示文本内容,还是需要支持其他操作(如复制、搜索、保存等)?当前按最简单的文本提取功能实现。
|
||||
|
||||
24
resources/seq_flow/20260326175651.mmd
Normal file
24
resources/seq_flow/20260326175651.mmd
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
sequenceDiagram
|
||||
participant M as Main
|
||||
participant AP as argparse
|
||||
participant PO as PDFOpener
|
||||
participant PR as PdfReader(pypdf)
|
||||
|
||||
M->>AP: parse_args()
|
||||
AP-->>M: args(file_path, start_page, end_page)
|
||||
M->>PO: __init__(file_path, start_page, end_page)
|
||||
M->>PO: run()
|
||||
PO->>PO: open()
|
||||
PO->>PR: PdfReader(file_path)
|
||||
PR-->>PO: reader
|
||||
PO->>PO: get_info(reader)
|
||||
PR-->>PO: info(num_pages, metadata)
|
||||
PO->>PO: display_info(info)
|
||||
PO-->>M: print info to console
|
||||
PO->>PO: extract_text(reader)
|
||||
loop for each page in range
|
||||
PR-->>PO: page.extract_text()
|
||||
end
|
||||
PO->>PO: display_text(texts)
|
||||
PO-->>M: print text to console
|
||||
63
resources/system_design/20260326175651.md
Normal file
63
resources/system_design/20260326175651.md
Normal file
@@ -0,0 +1,63 @@
|
||||
## Implementation approach
|
||||
|
||||
使用pypdf库实现PDF文件的读取和文本提取,该库安装简单、API直观,完全满足'尽量简单'的要求。程序通过Python标准库argparse接收命令行参数,支持指定PDF文件路径和可选的页码范围。异常处理使用Python内置异常机制,覆盖文件不存在、格式错误、权限不足等常见情况。整个程序只需一个主文件,依赖最小化。
|
||||
|
||||
## File list
|
||||
|
||||
- main.py
|
||||
|
||||
## Data structures and interfaces
|
||||
|
||||
|
||||
classDiagram
|
||||
class PDFOpener {
|
||||
-str file_path
|
||||
-int start_page
|
||||
-int end_page
|
||||
+__init__(file_path: str, start_page: int, end_page: int)
|
||||
+open() PdfReader
|
||||
+get_info(reader: PdfReader) dict
|
||||
+extract_text(reader: PdfReader) list[str]
|
||||
+display_info(info: dict) None
|
||||
+display_text(texts: list[str]) None
|
||||
+run() None
|
||||
}
|
||||
class Main {
|
||||
+parse_args() argparse.Namespace
|
||||
+main() None
|
||||
}
|
||||
Main --> PDFOpener : creates and uses
|
||||
|
||||
|
||||
## Program call flow
|
||||
|
||||
|
||||
sequenceDiagram
|
||||
participant M as Main
|
||||
participant AP as argparse
|
||||
participant PO as PDFOpener
|
||||
participant PR as PdfReader(pypdf)
|
||||
|
||||
M->>AP: parse_args()
|
||||
AP-->>M: args(file_path, start_page, end_page)
|
||||
M->>PO: __init__(file_path, start_page, end_page)
|
||||
M->>PO: run()
|
||||
PO->>PO: open()
|
||||
PO->>PR: PdfReader(file_path)
|
||||
PR-->>PO: reader
|
||||
PO->>PO: get_info(reader)
|
||||
PR-->>PO: info(num_pages, metadata)
|
||||
PO->>PO: display_info(info)
|
||||
PO-->>M: print info to console
|
||||
PO->>PO: extract_text(reader)
|
||||
loop for each page in range
|
||||
PR-->>PO: page.extract_text()
|
||||
end
|
||||
PO->>PO: display_text(texts)
|
||||
PO-->>M: print text to console
|
||||
|
||||
|
||||
## Anything UNCLEAR
|
||||
|
||||
当前需求已较为清晰,按最简单的文本提取功能实现。程序仅支持文本内容提取和基本信息展示,不支持复制、搜索、保存等高级操作。若后续需要支持加密PDF的解密或表格提取,可考虑升级为pdfplumber或pymupdf库。
|
||||
|
||||
Reference in New Issue
Block a user