Skip to main content

PDFToImageContent

Convert PDF files to ImageContent objects for multimodal AI processing.

Basic Information

  • Type: haystack.components.converters.image.PDFToImageContent
  • Components it can connect with:
    • FilesInput: PDFToImageContent can receive PDF files from FilesInput.
    • FileTypeRouter: PDFToImageContent can receive filtered PDF files from FileTypeRouter.
    • ChatPromptBuilder: PDFToImageContent can send extracted page images to ChatPromptBuilder to include in the prompt.

Inputs

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]List of PDF file paths or ByteStream objects to convert.
metaOptional[Union[Dict[str, Any], List[Dict[str, Any]]]]NoneOptional metadata to attach to the ImageContent objects. This value can be a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the metadata of all produced ImageContent objects. If it's a list, its length must match the number of sources as they're zipped together. For ByteStream objects, their meta is added to the output ImageContent objects.
detailOptional[Literal["auto", "high", "low"]]NoneOptional detail level of the image (only supported by OpenAI).
Possible values:
- "auto"
- "high"
- "low"
This is passed to the created ImageContent objects.
sizeOptional[Tuple[int, int]]NoneIf provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. If not provided, the size value is the one set in the constructor.
page_rangeOptional[List[Union[str, int]]]NoneList of page numbers and page ranges to convert to images. If not provided, the page range is the one set in the pipeline configuration.

Outputs

ParameterTypeDefaultDescription
image_contentsList[ImageContent]A list of ImageContent objects created from the PDF pages.

Overview

PDFToImageContent reads PDF files and converts specified pages into images, creating ImageContent objects containing the base64-encoded image data along with associated metadata.

PDFToImageContent can process specific pages or page ranges from PDF documents and supports various configuration options for image quality and size optimization. Each converted page becomes a separate ImageContent object with metadata indicating the source file and page number.

Image resizing helps reduce file size, memory usage, and processing time, which is beneficial when working with models that have resolution constraints or when transmitting images to remote services.

Usage Example

Initializing the Component

components:
PDFToImageContent:
type: haystack.components.converters.image.pdf_to_image.PDFToImageContent
init_parameters:
detail: high
size: [800, 600]
page_range: [1, 2, 3]

Parameters

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
detailOptional[Literal["auto", "high", "low"]]NoneOptional detail level of the image (only supported by OpenAI).
Possible values:
- "auto"
- "high"
- "low"
This is passed to the created ImageContent objects.
sizeOptional[Tuple[int, int]]NoneIf provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. This reduces file size, memory usage, and processing time.
page_rangeOptional[List[Union[str, int]]]NoneList of page numbers and page ranges to convert to images. Page numbers start at 1. If None, all pages in the PDF are converted. Also accepts printable range strings, for example:: ['1-3', '5', '8', '10-12'].

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]List of PDF file paths or ByteStream objects to convert.
metaOptional[Union[Dict[str, Any], List[Dict[str, Any]]]]NoneOptional metadata to attach to the ImageContent objects. This value can be a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the metadata of all produced ImageContent objects. If it's a list, its length must match the number of sources as they're zipped together. For ByteStream objects, their meta is added to the output ImageContent objects.
detailOptional[Literal["auto", "high", "low"]]NoneOptional detail level of the image (only supported by OpenAI). This is passed to the created ImageContent objects. If not provided, the detail level is the one set in the constructor.
sizeOptional[Tuple[int, int]]NoneIf provided, resizes the image to fit within the specified dimensions (width, height) while maintaining aspect ratio. If not provided, the size value is the one set in the constructor.
page_rangeOptional[List[Union[str, int]]]NoneList of page numbers and page ranges to convert to images. Page numbers start at 1. If None, all pages in the PDF are converted. Pages outside the valid range are skipped with a warning. Also accepts printable range strings, for example: ['1-3', '5', '8', '10-12'].