Skip to main content
Compatibility: Only available on Node.js.
This notebook provides a quick overview for getting started with PDFLoader document loaders. For detailed documentation of all PDFLoader features and configurations head to the API reference.

概述

集成详情

设置

要访问 PDFLoader document loader,你需要install the @langchain/community integration, along with the pdf-parse package.

凭证

安装

LangChain 的 PDFLoader 集成位于 @langchain/community 包中:

实例化

Now we can instantiate our model object and load documents:

Load

Usage, one document per file

Usage, custom pdfjs build

By default we use the pdfjs build bundled with pdf-parse, which is compatible with most environments, including Node.js and modern browsers. If you want to use a more recent version of pdfjs-dist or if you want to use a custom build of pdfjs-dist, you can do so by providing a custom pdfjs function that returns a promise that resolves to the PDFJS object. In the following example we use the “legacy” (see pdfjs docs) build of pdfjs-dist, which includes several polyfills not included in the default build.

Eliminating extra spaces

PDFs come in many varieties, which makes reading them a challenge. The loader parses individual text elements and joins them together with a space by default, but if you are seeing excessive spaces, this may not be the desired behavior. In that case, you can override the separator with an empty string like this:

Loading directories


API 参考

有关所有 PDFLoader 功能和配置的详细文档,请前往 API 参考