Skip to main content

legacy_pptx_api/
legacy_pptx_api.rs

1//! Legacy PPTX-only API retained for existing integrations.
2//!
3//! New code should use `PresentationContainer`; see `basic_usage.rs`.
4//!
5//! Run with:
6//! cargo run --example legacy_pptx_api <presentation.pptx> [output.md]
7
8use pptx_to_md::{ParserConfig, PptxContainer, Result};
9use std::env;
10use std::fs;
11use std::path::Path;
12
13fn main() -> Result<()> {
14    let args: Vec<String> = env::args().collect();
15    let Some(input_path) = args.get(1) else {
16        eprintln!("Usage: cargo run --example legacy_pptx_api <presentation.pptx> [output.md]");
17        return Ok(());
18    };
19    let output_path = args.get(2).map(String::as_str).unwrap_or("output.md");
20
21    // This is the pre-PresentationContainer flow: open a PPTX-specific
22    // container, parse every slide, and render each slide separately. It does
23    // not add the presentation-level metadata header.
24    let mut container = PptxContainer::open(Path::new(input_path), ParserConfig::default())?;
25    let markdown = container
26        .parse_all()?
27        .into_iter()
28        .map(|slide| slide.convert_to_md())
29        .collect::<Result<Vec<_>>>()?
30        .join("\n");
31    fs::write(output_path, markdown)?;
32
33    println!("Converted PPTX with the legacy entry point to {output_path}");
34    Ok(())
35}