Skip to content

Commit

Permalink
Add one more alternative for loading PDFLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Apr 10, 2023
1 parent 299d647 commit 9245c7b
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,31 @@ const docs = await loader.load();

## Usage, legacy environments

In legacy environments, you can use the `pdfjs` option to provide a function that returns a promise that resolves to the `PDFJS` object. This is useful if you want to use a custom build of `pdfjs-dist` or if you want to use a different version of `pdfjs-dist`. Eg. here we use the legacy build of `pdfjs-dist`, which includes several polyfills that are not included in the default build.
In legacy environments, you can use the `pdfjs` option to provide a function that returns a promise that resolves to the `PDFJS` object. This is useful if you want to use a custom build of `pdfjs-dist` or if you want to use a different version of `pdfjs-dist`.

Here we use the legacy build of `pdfjs-dist`, which includes several polyfills not included in the default build.

```typescript
import { PDFLoader } from "langchain/document_loaders/fs/pdf";

const loader = new PDFLoader("src/document_loaders/example_data/example.pdf", {
// you may need to add `.then(m => m.default)` to the end of the import
pdfjs: () => import("pdfjs-dist/legacy/build/pdf.js"),
});
```

Alternatively, if the legacy build of `pdfjs-dist` doesn't work for you, you can use an older version bundled with `pdf-parse`:

```bash npm2yarn
npm rm pdfjs-dist # if you had installed it before
npm install pdf-parse
```

```typescript
import { PDFLoader } from "langchain/document_loaders/fs/pdf";

const loader = new PDFLoader("src/document_loaders/example_data/example.pdf", {
// you may need to add `.then(m => m.default)` to the end of the import
pdfjs: () => import("pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js"),
});
```

0 comments on commit 9245c7b

Please sign in to comment.