AS AgentScopeAPI 手册 / API Reference
类class agentscope.rag

PDFParser

class PDFParser(ParserBase)
源码Source agentscope/rag/_parser/_pdf.py:16–94

用于PDF 文件的解析器。位于 agentscope.rag 包,继承自 ParserBase。核心成员包括 supported_extensions、parse。

Returns one :class:Section per page. Empty / image-only pages still produce a Section (with empty text) so the page → section correspondence stays exact — downstream chunkers naturally drop empty content.

Requires :mod:pypdf; install with pip install pypdf (or via the agentscope[rag] extra).

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
supported_media_typeslist[str]
`supported_media_types` 字段。
['application/pdf']

方法摘要Method Summary

方法Method说明Description
def supported_extensions() -> list[str]
返回规范`.pdf`扩展。
Return the canonical ``.pdf`` extension.
async def parse(file: bytes | str, filename: str) -> list[Section]async
执行解析相关操作。
Read the PDF bytes and return one Section per page.

属性详情Attribute Detail

supported_media_types

list[str] = ['application/pdf']

supported_media_types 字段。声明为 list[str]。

The supported media types field.

源码Source agentscope/rag/_parser/_pdf.py:28

方法详情Method Detail

supported_extensions

def supported_extensions() -> list[str]

返回规范.pdf扩展。

Return the canonical .pdf extension.

返回Returns list[str]
返回str列表。Returns a list of str.
源码Source agentscope/rag/_parser/_pdf.py:31–33

parse

async def parse(file: bytes | str, filename: str) -> list[Section]
async

执行解析相关操作。

Read the PDF bytes and return one Section per page.

参数Parameters
名称Name类型Type说明Description
filebytes | str文件(类型 `bytes | str`)。Either the raw PDF bytes, or a filesystem path to the PDF file.
filenamestrfilename(类型 `str`)。The source filename, copied verbatim into each Section's :attr:`Section.source` field.
返回Returns list[Section]
返回Section列表。`list[Section]`:
异常Raises
  • 可能抛出 `Exception`。`FileNotFoundError`: If `file` is a `str` pointing to
  • 可能抛出 `Exception`。a path that does not exist.
  • 可能抛出 `Exception`。`ImportError`: If :mod:`pypdf` is not installed.
  • 可能抛出 `Exception`。`ValueError`: If the bytes cannot be parsed as PDF.
源码Source agentscope/rag/_parser/_pdf.py:35–94
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.