mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-19 22:11:41 +00:00
Different PDF libraries have different strengths and weaknesses. PyMuPDF does a good job at extracting the most amount of content from the doc, regardless of the source quality, extremely fast (especially compared to Unstructured). https://pymupdf.readthedocs.io/en/latest/index.html
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from pathlib import Path
|
|
|
|
from langchain.document_loaders import (
|
|
PDFMinerLoader,
|
|
PyMuPDFLoader,
|
|
UnstructuredPDFLoader,
|
|
)
|
|
|
|
|
|
def test_unstructured_pdf_loader() -> None:
|
|
"""Test unstructured loader."""
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = UnstructuredPDFLoader(str(file_path))
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == 1
|
|
|
|
|
|
def test_pdfminer_loader() -> None:
|
|
"""Test PDFMiner loader."""
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = PDFMinerLoader(str(file_path))
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == 1
|
|
|
|
file_path = Path(__file__).parent.parent / "examples/layout-parser-paper.pdf"
|
|
loader = PDFMinerLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
|
|
|
|
def test_pymupdf_loader() -> None:
|
|
"""Test PyMuPDF loader."""
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = PyMuPDFLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
|
|
file_path = Path(__file__).parent.parent / "examples/layout-parser-paper.pdf"
|
|
loader = PyMuPDFLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 16
|