Get all the text in a slide in a presentation

This example reads DrawingML text runs from one slide part in a PresentationML package.

Slide text is normally stored in a:t elements inside shapes, placeholders, tables, SmartArt, charts, and other DrawingML containers. This simple example reads the raw slide XML and extracts a:t element text.

The upstream sample returns one string per paragraph by walking paragraphs and concatenating each paragraph's text runs. The Rust listing below is intentionally smaller: it returns the individual a:t text values in document order for the selected slide.

Read slide text

#![allow(unused)]
fn main() {
pub fn get_slide_text(
  path: &Path,
  slide_index: usize,
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
  let document = PresentationDocument::new_from_file_with_settings(path, lazy_settings())?;
  let presentation_part = document.presentation_part()?;
  let Some(slide_part) = presentation_part.slide_parts(&document).nth(slide_index) else {
    return Ok(Vec::new());
  };
  let xml = slide_part.data_as_str(&document)?.unwrap_or_default();

  Ok(extract_drawing_text(xml))
}
}

The function:

  1. Opens the presentation package lazily.
  2. Gets the presentation part.
  3. Selects a slide by zero-based index from slide_parts.
  4. Reads the slide part XML.
  5. Returns the text values found in a:t elements.

If the index is out of range, it returns an empty vector.

Limitations

This helper is intentionally lightweight. It is suitable for simple extraction and documentation examples, but it is not a full text model for PowerPoint. Production code may need to handle tables, charts, notes, comments, ordering rules, and XML whitespace more carefully.

When you need paragraph-level results, parse the slide root and group runs under each a:p paragraph instead of treating each a:t value as a paragraph.