Repository: langchain
Issue: PDFPlumber extract_images has problems on 1bit images
Labels: 🤖:bug

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.
- [X] I am sure that this is a bug in LangChain rather than my code.
- [X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

### Example Code

```
from langchain_community.document_loaders import PDFPlumberLoader

filename = "<pdf-file-scanned-to-1bit-bw.pdf>"
loader = PDFPlumberLoader(filename, extract_images=True)
docs = loader.load()
```



### Error Message and Stack Trace (if applicable)

langchain_community/document_loaders/parsers/pdf.py:456, in PDFPlumberParser._extract_images_from_page(self, page)
    453 for img in page.images:
    454     if img["stream"]["Filter"].name in _PDF_FILTER_WITHOUT_LOSS:
    455         images.append(
--> 456             np.frombuffer(img["stream"].get_data(), dtype=np.uint8).reshape(
    457                 img["stream"]["Height"], img["stream"]["Width"], -1
    458             )
    459         )
    460     elif img["stream"]["Filter"].name in _PDF_FILTER_WITH_LOSS:
    461         images.append(img["stream"].get_data())

ValueError: cannot reshape array of size 1052700 into shape (3300,2552,newaxis)

### Description

The problem is that the conversion to numpy array assumes 8bit (np.uint8), which is not correct on 1 bit images in the PDF.

You can get the information from the "stream" object:
```
print(img['stream'])
```
--> <PDFStream(321): raw=66079, {**'BitsPerComponent': 1**, 'ColorSpace': /'DeviceGray', 'DecodeParms': {'Columns': 2552, 'K': -1, 'Rows': 3300}, 'Filter': /'CCITTFaxDecode', 'Height': 3300, 'Subtype': /'Image', 'Type': /'XObject', 'Width': 2552, 'Length': 66079}>

A solution would be e.g. using PIL to get the image converted correctly:
```
from PIL import Image

if img["stream"]["BitsPerComponent"] == 1:
    images.append(
        np.array(Image.frombytes("1", (img["stream"]["Width"], img["stream"]["Height"]), img["stream"].get_data()).convert("L")
        )
    )
```


### System Info

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000
> Python Version:  3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information
-------------------
> langchain_core: 0.3.21
> langchain: 0.3.9
> langchain_community: 0.3.9
> langsmith: 0.1.147
> langchain_ollama: 0.2.0
> langchain_text_splitters: 0.3.2

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp: 3.9.3
> async-timeout: Installed. No version info available.
> dataclasses-json: 0.6.4
> httpx: 0.27.2
> httpx-sse: 0.4.0
> jsonpatch: 1.33
> langsmith-pyo3: Installed. No version info available.
> numpy: 1.26.4
> ollama: 0.4.1
> orjson: 3.10.12
> packaging: 23.2
> pydantic: 2.10.2
> pydantic-settings: 2.6.1
> PyYAML: 6.0.1
> requests: 2.31.0
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.25
> tenacity: 8.2.3
> typing-extensions: 4.12.2