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[structured-document]''"
        ) 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"]

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

        # 2. Iterate remaining layout blocks
        for shape in slide.shapes:
            if shape == slide.shapes.title:
                continue

            # Handle Table blocks
            if hasattr(shape, "has_table") and shape.has_table:
                table_md = self._extract_table(shape)
                if table_md:
                    slide_content.append(table_md)

            # Handle Chart blocks
            elif hasattr(shape, "has_chart") and shape.has_chart:
                chart_md = self._extract_chart(shape)
                if chart_md:
                    slide_content.append(chart_md)

            # Handle text boxes & paragraphs
            elif hasattr(shape, "has_text_frame") and shape.has_text_frame:
                text_md = self._extract_text(shape)
                if text_md:
                    slide_content.append(text_md)

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

        # Package slide buffer string cleanly
        yield "\n".join(slide_content).strip()