Get all the text in all slides in a presentation

This example iterates over every slide part in a PresentationML package and extracts DrawingML text from each slide.

Read all slide text

#![allow(unused)]
fn main() {
pub fn get_all_slide_text(path: &Path) -> Result<Vec<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 mut slides = Vec::new();

  let slide_parts: Vec<_> = presentation_part.slide_parts(&document).collect();
  for slide_part in slide_parts {
    let xml = slide_part.data_as_str(&document)?.unwrap_or_default();
    slides.push(extract_drawing_text(xml));
  }

  Ok(slides)
}
}

The function returns one Vec<String> per slide. Each inner vector contains the text values found in a:t elements for that slide.

The upstream sample presents the result as slide IDs paired with paragraph strings. This Rust listing keeps the output as nested vectors of extracted DrawingML text values.

This keeps package traversal explicit:

  • Open the package with PresentationDocument.
  • Get the main presentation part.
  • Iterate presentation_part.slide_parts(&document).
  • Read each slide part's XML payload.

Ordering

This example uses the order returned by the package relationship model. For workflows that require exact presentation order or slide IDs, inspect the presentation root's slide ID list and resolve each relationship ID in that order.

Limitations

The helper reads visible text in simple a:t elements. It does not interpret PowerPoint layout inheritance, notes pages, charts, SmartArt, comments, or accessibility metadata.