Skip to content

chunklet.document_chunker.processors.pptx_processor

Classes:

  • PPTXProcessor –

    Processor class for extracting text, tables, charts, notes, and metadata from PPTX files.

PPTXProcessor

PPTXProcessor(file_path: str)

Bases: BaseProcessor

Processor class for extracting text, tables, charts, notes, and metadata from PPTX files.

Text content is extracted sequentially slide-by-slide. Structural elements like slide titles are converted to Markdown headers, bullet points maintain indentation, presentation tables are structured into valid Markdown tables, visual charts are transformed into text grids, and presenter notes are appended at the bottom of each slide block.

This processor focuses on extracting core metadata following the OpenXML Document CoreProperties format, matching common practice in office document types.

For more details on PPTX layout elements, refer to the python-pptx documentation: https://python-pptx.readthedocs.io/

Initializes the PPTXProcessor with a path to the PPTX file and reads the presentation into memory.

Parameters:

  • file_path

    (str) –

    Path to the PPTX file.

Methods:

  • extract_metadata –

    Extracts OpenXML Document CoreProperties from the PPTX file

  • extract_text –

    Yields fully converted Markdown content slide-by-slide from the PPTX archive.

Source code in src/chunklet/document_chunker/processors/pptx_processor.py
def __init__(self, file_path: str):
    """
    Initializes the PPTXProcessor with a path to the PPTX file
    and reads the presentation into memory.

    Args:
        file_path: Path to the PPTX file.
    """
    super().__init__(file_path)
    try:
        from pptx import Presentation
    except ImportError as e:  # pragma: no cover
        raise ImportError(
            "The 'python-pptx' library is not installed. "
            "Please install it with 'pip install python-pptx>=1.0.0' or install the document processing extras "
            "with 'pip install 'chunklet-py[struct-doc]''"
        ) from e

    self.prs = Presentation(file_path)

extract_metadata

extract_metadata() -> dict[str, Any]

Extracts OpenXML Document CoreProperties from the PPTX file based on the defined METADATA_FIELDS class schema.

Returns:

  • dict[str, Any] –

    A dictionary containing metadata fields.

Source code in src/chunklet/document_chunker/processors/pptx_processor.py
def extract_metadata(self) -> dict[str, Any]:
    """
    Extracts OpenXML Document CoreProperties from the PPTX file
    based on the defined METADATA_FIELDS class schema.

    Returns:
        A dictionary containing metadata fields.
    """
    meta = self.prs.core_properties
    metadata = {"source": str(self.file_path)}

    for field in self.METADATA_FIELDS:
        # Handle cases where property might not exist in an older python-pptx build
        if not hasattr(meta, field):
            continue

        val = getattr(meta, field, None)
        if val:
            metadata[field] = str(val)

    return metadata

extract_text

extract_text() -> Generator[str, None, None]

Yields fully converted Markdown content slide-by-slide from the PPTX archive.

Yields:

  • str –

    Markdown-formatted rendering of each slide.

Source code in src/chunklet/document_chunker/processors/pptx_processor.py
def extract_text(self) -> Generator[str, None, None]:
    """
    Yields fully converted Markdown content slide-by-slide from the PPTX archive.

    Yields:
        Markdown-formatted rendering of each slide.
    """
    for slide_idx, slide in enumerate(self.prs.slides, start=1):
        slide_content = [f"\n<!-- Slide {slide_idx} -->\n"]

        # Title
        if title := self._extract_slide_title(slide):
            slide_content.append(title)

        # Layout blocks
        slide_content.extend(self._extract_layout_blocks(slide))

        # Presenter Notes
        if notes_md := self._extract_notes(slide):
            slide_content.append(notes_md)

        yield "\n".join(slide_content).strip()