Converts documents between formats for LLM consumption.
Currently supports:
- PDF → PNG (first page only, 150 DPI)
Usage
PDF-to-image conversion is used for:
- OpenAI: Chat API only supports images (PDFs work in Assistants API)
- Ollama: Vision models require image formats
Native PDF support:
- Anthropic Claude 4.5+: Supports PDFs via document API
Requirements
Requires ImageMagick v7+ to be installed:
- macOS:
brew install imagemagick - Ubuntu/Debian:
apt-get install imagemagick - Docker: Install in runtime image
Configuration
The conversion adapter can be configured in config files:
config :aludel, :document_converter,
adapter: Aludel.Interfaces.DocumentConverter.Adapters.ImagemagickFor testing, use a stub adapter.
Summary
Functions
Converts a PDF document to PNG format.
Types
Functions
@spec pdf_to_image(document()) :: convert_result()
Converts a PDF document to PNG format.
Only converts the first page at 150 DPI for optimal text readability. Creates temporary files for conversion and cleans them up afterwards.
Examples
iex> pdf_doc = %{data: pdf_binary, content_type: "application/pdf"}
iex> {:ok, png_doc} = DocumentConverter.pdf_to_image(pdf_doc)
iex> png_doc.content_type
"image/png"
iex> image_doc = %{data: png_binary, content_type: "image/png"}
iex> {:ok, ^image_doc} = DocumentConverter.pdf_to_image(image_doc)
:ok