PyPDFLoader#
- class langchain_community.document_loaders.pdf.PyPDFLoader(file_path: str, password: str | bytes | None = None, headers: Dict | None = None, extract_images: bool = False, *, extraction_mode: str = 'plain', extraction_kwargs: Dict | None = None)[source]#
PyPDFLoader 文档加载器集成
- Setup:
安装
langchain-community
。pip install -U langchain-community
- Instantiate:
from langchain_community.document_loaders import PyPDFLoader loader = PyPDFLoader( file_path = "./example_data/layout-parser-paper.pdf", password = "my-password", extract_images = True, # headers = None # extraction_mode = "plain", # extraction_kwargs = None, )
- Lazy load:
docs = [] docs_lazy = loader.lazy_load() # async variant: # docs_lazy = await loader.alazy_load() for doc in docs_lazy: docs.append(doc) print(docs[0].page_content[:100]) print(docs[0].metadata)
LayoutParser : A Unified Toolkit for Deep Learning Based Document Image Analysis Zejiang Shen1( ), R {'source': './example_data/layout-parser-paper.pdf', 'page': 0}
- Async load:
docs = await loader.aload() print(docs[0].page_content[:100]) print(docs[0].metadata)
LayoutParser : A Unified Toolkit for Deep Learning Based Document Image Analysis Zejiang Shen1( ), R {'source': './example_data/layout-parser-paper.pdf', 'page': 0}
使用文件路径进行初始化。
属性
source
方法
__init__
(file_path[, password, headers, ...])使用文件路径进行初始化。
一个用于文档的懒加载器。
aload
()将数据加载到Document对象中。
懒加载给定路径作为页面。
load
()将数据加载到Document对象中。
load_and_split
([text_splitter])加载文档并将其分割成块。
- Parameters:
file_path (str)
password (str | bytes | None)
headers (Dict | None)
extract_images (bool)
extraction_mode (str)
extraction_kwargs (Dict | None)
- __init__(file_path: str, password: str | bytes | None = None, headers: Dict | None = None, extract_images: bool = False, *, extraction_mode: str = 'plain', extraction_kwargs: Dict | None = None) None [source]#
使用文件路径进行初始化。
- Parameters:
file_path (str)
password (str | bytes | None)
headers (Dict | None)
extract_images (bool)
extraction_mode (str)
extraction_kwargs (Dict | None)
- Return type:
无
- load_and_split(text_splitter: TextSplitter | None = None) list[Document] #
加载文档并将其分割成块。块以文档形式返回。
不要重写此方法。它应该被视为已弃用!
- Parameters:
text_splitter (可选[TextSplitter]) – 用于分割文档的TextSplitter实例。 默认为RecursiveCharacterTextSplitter。
- Returns:
文档列表。
- Return type:
列表[Document]
使用 PyPDFLoader 的示例