Skip to content

Recipe: PDF Processing Pipeline

Goal

Convert PDFs to images and/or extracted text before using downstream agent workflows.

Example: convert PDF pages to images

from doc_processing_toolkit.pdf_processor import pdf_to_images

pages = pdf_to_images(
    pdf_path="sample.pdf",
    output_dir="output_images",
    dpi=300,
    return_images=False,
)
print(len(pages))

Example: recursive directory processing

from doc_processing_toolkit.pdf_processor import process_all_pdfs

count = process_all_pdfs(
    root_directory="./documents",
    dpi=300,
    return_images=False,
)
print(count)

Example: LLM Whisperer extraction

from doc_processing_toolkit.pdf_processor import process_pdf_with_llm_whisperer

page_text = process_pdf_with_llm_whisperer(
    pdf_path="sample.pdf",
    output_dir="output_text",
    return_extracted_text=True,
)
print(len(page_text))

A document LLMWhisperer cannot process — a corrupt PDF, for instance — makes the service report failed and then error on every status poll. process_pdf_with_llm_whisperer raises the client's own LLMWhispererClientException for those statuses, carrying the status payload (the service's error_in_ingestion message names the parse failure) and its HTTP status code; before 2026-09-23 the poll loop only printed them and never returned. A plain-text file with a .pdf name is not an error to the service: it is extracted as text and returned like any other document.

What to validate

  • PDF conversion returns expected page count
  • image/text outputs are generated in expected locations
  • OCR extraction path respects configured environment variables

Test sources

  • tests/integration/test_pdf_processor.py
  • tests/fixtures/sample_files/README.md