# PDF Conversion

## ❗Make sure you import the library as the following

```python
from imageconvert import ImageConvert
```

***

📄 **pdf\_to\_images()**

```python
ImageConvert.pdf_to_images(
    pdf_path,    # str/Path
    output_dir,  # str/Path
    format='.jpg',
    quality=95,
    dpi=300,
    pages=None
)
```

**Description**\
Render each page of a PDF file into a high‑resolution image.

**Parameters**

* `pdf_path` (`str`/`Path`): Path to the source PDF file.
* `output_dir` (`str`/`Path`): Directory to save the rendered images. Created if missing.
* `format` (`str`): Output image extension (e.g. `'.jpg'`, `'.png'`). Defaults to `'.jpg'`.
* `quality` (`int`): JPEG/WebP quality (1–100). Ignored for PNG. Defaults to `95`.
* `dpi` (`int`): Rendering resolution in dots per inch. Defaults to `300`.
* `pages` (`List[int]`/`None`): Zero‑based page indices to export. `None` exports all pages.

**Returns**\
`List[str]`: Paths of generated image files in page order.

**Raises**

* `FileNotFoundError`: Input PDF not found.
* `ValueError`: PDF has no pages or no valid page indices.

**Example**

```python
pages = ImageConvert.pdf_to_images(
    pdf_path='document.pdf',
    output_dir='out_images',
    format='.png',
    quality=80,
    dpi=200
)
print(pages)
```

***

📑 **images\_to\_pdf()**

```python
ImageConvert.images_to_pdf(
    image_paths,  # List[str|Path]
    output_pdf,   # str/Path
    page_size='A4',
    fit_method='contain',
    quality=95,
    metadata=None
)
```

**Description**\
Combine multiple image files into a single PDF document, placing one image per page.

**Parameters**

* `image_paths` (`List[str|Path]`): Ordered list of image file paths.
* `output_pdf` (`str`/`Path`): Destination path for the PDF.
* `page_size` (`str`): Page size code (e.g. `'A4'`, `'letter'`). Defaults to `'A4'`.
* `fit_method` (`str`): How to fit images:
  * `'contain'`: preserve aspect ratio and center (default)
  * `'cover'`: fill page, cropping if needed
  * `'stretch'`: scale to page dimensions
* `quality` (`int`): JPEG quality (1–100) for embedded images. Defaults to `95`.
* `metadata` (`Dict[str,str]`/`None`): PDF metadata fields: `title`, `author`, `subject`, `keywords`, `creator`.

**Returns**\
`str`: Path to the created PDF file.

**Raises**

* `FileNotFoundError`: One or more image files not found.
* `ValueError`: No valid images provided.

**Example**

```python
pdf = ImageConvert.images_to_pdf(
    image_paths=['img1.png', 'img2.jpg'],
    output_pdf='album.pdf',
    page_size='letter',
    fit_method='cover',
    quality=90,
    metadata={'title':'Album','author':'Ricardo'}
)
print(pdf)
```
