Skip to main content

basic_usage/
basic_usage.rs

1//! Preferred PPTX/ODP to Markdown conversion.
2//!
3//! Run with: cargo run --example basic_usage <presentation.pptx|presentation.odp> [output.md]
4
5use pptx_to_md::{ParserConfig, PresentationContainer, Result};
6use std::env;
7use std::fs;
8use std::path::Path;
9
10fn main() -> Result<()> {
11    let args: Vec<String> = env::args().collect();
12    let pptx_path = if args.len() > 1 {
13        &args[1]
14    } else {
15        eprintln!("Usage: cargo run --example basic_usage <presentation.pptx|presentation.odp> <extract_images>\ncargo run --example basic_usage sample.pptx true");
16        return Ok(());
17    };
18
19    // Tries to read if the extract_images flag is false else set to true
20    let extract_images = if args.len() > 2 {
21        !(args[2] == "false" || args[2] == "False" || args[2] == "0")
22    } else {
23        true
24    };
25
26    let config = ParserConfig::builder()
27        .extract_images(extract_images)
28        .include_presentation_metadata(true)
29        .include_comments(true)
30        .include_speaker_notes(true)
31        .build();
32    let mut container = PresentationContainer::open(Path::new(pptx_path), config)?;
33    let markdown = container.convert_to_md()?;
34
35    fs::write("output.md", markdown)?;
36    println!("Converted {:?} presentation to output.md", container.format());
37    Ok(())
38}