Skip to main content

save_images/
save_images.rs

1//! Save presentation images next to the generated Markdown instead of embedding them.
2//!
3//! Run with:
4//! cargo run --example save_images <presentation.pptx|presentation.odp> [image-directory] [output.md]
5
6use pptx_to_md::{ImageHandlingMode, ParserConfig, PresentationContainer, Result};
7use std::env;
8use std::fs;
9use std::path::{Path, PathBuf};
10
11fn main() -> Result<()> {
12    let args: Vec<String> = env::args().collect();
13    let Some(input_path) = args.get(1) else {
14        eprintln!(
15            "Usage: cargo run --example save_images <presentation.pptx|presentation.odp> [image-directory] [output.md]"
16        );
17        return Ok(());
18    };
19    let image_directory = args
20        .get(2)
21        .map(PathBuf::from)
22        .unwrap_or_else(|| PathBuf::from("extracted_images"));
23    let output_path = args.get(3).map(String::as_str).unwrap_or("output.md");
24
25    let config = ParserConfig::builder()
26        .image_handling_mode(ImageHandlingMode::Save)
27        .image_output_path(image_directory)
28        .build();
29    let mut presentation = PresentationContainer::open(Path::new(input_path), config)?;
30
31    fs::write(output_path, presentation.convert_to_md()?)?;
32    println!("Saved Markdown to {output_path}");
33    Ok(())
34}