LayoutLMv3 image preparation code snippet does not work with PDFs
Author: joehoover
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.20.1
- Platform: macOS-10.16-x86_64-i386-64bit
- Python version: 3.9.12
- Huggingface_hub version: 0.8.1
- PyTorch version (GPU?): 1.12.0 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>


### Who can help?

@NielsRogge

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

This is not a bug per se, but I wasn't sure how else to file it. The official LayoutLMv3 Transformers documentation indicates that PDF files can be directly processed; however, they can't -- at least, not with the current code snippets.

For example, this [code snippet](https://huggingface.co/docs/transformers/model_doc/layoutlmv3#transformers.LayoutLMv3FeatureExtractor.__call__.example) has the lines:

```
from PIL import Image

image = Image.open("name_of_your_document - can be a png file, pdf, etc.").convert("RGB")
```

However, `PIL.Image` cannot open PDFs. In fact, the [Pillow documentation](https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html?highlight=pdf#:~:text=.palm.-,PDF,-%23) indicates that PDFs are only writable. 

Reproduction is trivial, but, for completeness: 

1. Download this pdf: https://slicedinvoices.com/pdf/wordpress-pdf-invoice-plugin-sample.pdf
2. Install Pillow: `pip install pillow`
3. Run this code:

```python
from PIL import Image
image = Image.open(<path_to_invoice.pdf>).convert("RGB")
```
Expected error:
```
UnidentifiedImageError: cannot identify image file '/Users/joe/Downloads/wordpress-pdf-invoice-plugin-sample.pdf'
```


### Expected behavior

The documentation should provide a working solution for processing PDFs. 

I did notice that the `__call__` implementation of the `LayoutLMv3FeatureExtractor` has an `images` argument that accepts numpy arrays and torch tensors, in addition to Image objects. So, I assume one or more of the following options is the correct workflow: 

1. Read PDFs into a python object that can be converted to an PIL.Image type.
2. Read/transform PDFs into an array as expected by the feature extractor. 
3. Convert PDFs to an image and proceed with PIL.Image

However, as I'm new to document intelligence and modeling PDFs, I'll have to do some digging to identify the right solution. So, it would be nice if the documentation was updated so that others won't have to do the same. 

One work-around (or solution?) is to just convert the PDF to an image, e.g.: 

```python
import io
from wand.image import Image as WImage
import PIL

local_path = "/Users/joe/Downloads/wordpress-pdf-invoice-plugin-sample.pdf"

img = WImage(filename=local_path, resolution=100) # bigger
image = PIL.Image.open(io.BytesIO(img.make_blob("png"))).convert("RGB")
```

It also [looks like](https://stackoverflow.com/questions/47599012/how-to-convert-a-wand-image-object-to-numpy-array-without-opencv) Wand supports exporting to Numpy `array`.

Comments:
cc @NielsRogge 

Yes, feel free to improve the docs as was done for LayoutLMv2 in #15293

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.