Skip to main content

styled_presentation/
styled_presentation.rs

1//! Example: Styled presentation with custom fonts and formatting
2//!
3//! Demonstrates text formatting capabilities
4//! Run with: cargo run --example styled_presentation
5
6use ppt_rs::generator::{SlideContent, create_pptx_with_content};
7use std::fs;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    println!("╔════════════════════════════════════════════════════════════╗");
11    println!("║     Generating Styled Presentation Examples               ║");
12    println!("╚════════════════════════════════════════════════════════════╝");
13    println!();
14
15    // Create output directory
16    fs::create_dir_all("examples/output")?;
17
18    // Example 1: Large title with small content
19    println!("1. Creating presentation with custom font sizes...");
20    create_large_title_example()?;
21    println!("   ✓ Created: examples/output/large_title.pptx");
22    println!();
23
24    // Example 2: Bold content
25    println!("2. Creating presentation with bold formatting...");
26    create_bold_content_example()?;
27    println!("   ✓ Created: examples/output/bold_content.pptx");
28    println!();
29
30    // Example 3: Mixed formatting
31    println!("3. Creating presentation with mixed formatting...");
32    create_mixed_formatting_example()?;
33    println!("   ✓ Created: examples/output/mixed_formatting.pptx");
34    println!();
35
36    println!("✅ All styled presentations generated successfully!");
37    println!();
38    println!("Generated files:");
39    println!("  - examples/output/large_title.pptx");
40    println!("  - examples/output/bold_content.pptx");
41    println!("  - examples/output/mixed_formatting.pptx");
42    println!();
43    println!("Open these files to see the text formatting in action!");
44    println!();
45
46    Ok(())
47}
48
49fn create_large_title_example() -> Result<(), Box<dyn std::error::Error>> {
50    let slides = vec![
51        SlideContent::new("Large Title Slide")
52            .title_size(60)  // 60pt title
53            .content_size(16) // 16pt content
54            .add_bullet("Small bullet point 1")
55            .add_bullet("Small bullet point 2")
56            .add_bullet("Small bullet point 3"),
57        SlideContent::new("Regular Formatting")
58            .add_bullet("Default 44pt title")
59            .add_bullet("Default 28pt content")
60            .add_bullet("Standard formatting"),
61    ];
62
63    let pptx_data = create_pptx_with_content("Large Title Example", slides)?;
64    fs::write("examples/output/large_title.pptx", pptx_data)?;
65    Ok(())
66}
67
68fn create_bold_content_example() -> Result<(), Box<dyn std::error::Error>> {
69    let slides = vec![
70        SlideContent::new("Bold Content Slide")
71            .title_bold(true)
72            .content_bold(true)  // Make bullets bold
73            .add_bullet("Bold bullet point 1")
74            .add_bullet("Bold bullet point 2")
75            .add_bullet("Bold bullet point 3"),
76        SlideContent::new("Regular Content")
77            .title_bold(true)
78            .content_bold(false)  // Regular bullets
79            .add_bullet("Regular bullet point 1")
80            .add_bullet("Regular bullet point 2"),
81    ];
82
83    let pptx_data = create_pptx_with_content("Bold Content Example", slides)?;
84    fs::write("examples/output/bold_content.pptx", pptx_data)?;
85    Ok(())
86}
87
88fn create_mixed_formatting_example() -> Result<(), Box<dyn std::error::Error>> {
89    let slides = vec![
90        SlideContent::new("Title Slide")
91            .title_size(52)
92            .title_bold(true)
93            .content_size(24)
94            .content_bold(false)
95            .add_bullet("Large content text")
96            .add_bullet("Still readable")
97            .add_bullet("Professional look"),
98        SlideContent::new("Compact Slide")
99            .title_size(36)
100            .title_bold(false)
101            .content_size(18)
102            .content_bold(true)
103            .add_bullet("Smaller title")
104            .add_bullet("Bold content")
105            .add_bullet("Tight spacing"),
106        SlideContent::new("Summary")
107            .title_size(48)
108            .title_bold(true)
109            .content_size(32)
110            .content_bold(true)
111            .add_bullet("Large bold text")
112            .add_bullet("High impact")
113            .add_bullet("Great for emphasis"),
114    ];
115
116    let pptx_data = create_pptx_with_content("Mixed Formatting Example", slides)?;
117    fs::write("examples/output/mixed_formatting.pptx", pptx_data)?;
118    Ok(())
119}