Skip to main content

advanced_features/
advanced_features.rs

1//! Example: Advanced PPTX features
2//!
3//! Demonstrates text formatting, shapes, and tables
4//! Run with: cargo run --example advanced_features
5
6use ppt_rs::generator::{
7    SlideContent,
8    create_pptx_with_content,
9};
10use std::fs;
11
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13    println!("╔════════════════════════════════════════════════════════════╗");
14    println!("║     Generating Advanced PPTX Examples                     ║");
15    println!("╚════════════════════════════════════════════════════════════╝");
16    println!();
17
18    // Create output directory
19    fs::create_dir_all("examples/output")?;
20
21    // Example 1: Text Formatting
22    println!("1. Creating presentation with text formatting...");
23    create_text_formatting_example()?;
24    println!("   ✓ Created: examples/output/text_formatting.pptx");
25    println!();
26
27    // Example 2: Shapes
28    println!("2. Creating presentation with shapes...");
29    create_shapes_example()?;
30    println!("   ✓ Created: examples/output/shapes_demo.pptx");
31    println!();
32
33    // Example 3: Tables
34    println!("3. Creating presentation with tables...");
35    create_tables_example()?;
36    println!("   ✓ Created: examples/output/tables_demo.pptx");
37    println!();
38
39    println!("✅ All advanced examples generated successfully!");
40    println!();
41    println!("Generated files:");
42    println!("  - examples/output/text_formatting.pptx");
43    println!("  - examples/output/shapes_demo.pptx");
44    println!("  - examples/output/tables_demo.pptx");
45    println!();
46
47    Ok(())
48}
49
50fn create_text_formatting_example() -> Result<(), Box<dyn std::error::Error>> {
51    let slides = vec![
52        SlideContent::new("Text Formatting Examples")
53            .add_bullet("Bold text demonstration")
54            .add_bullet("Italic text demonstration")
55            .add_bullet("Underlined text demonstration")
56            .add_bullet("Colored text demonstration"),
57        SlideContent::new("Font Sizes")
58            .add_bullet("Small text (12pt)")
59            .add_bullet("Normal text (18pt)")
60            .add_bullet("Large text (24pt)")
61            .add_bullet("Extra large text (32pt)"),
62        SlideContent::new("Combined Formatting")
63            .add_bullet("Bold and italic together")
64            .add_bullet("Colored and underlined text")
65            .add_bullet("Large bold red text")
66            .add_bullet("Small italic blue text"),
67    ];
68
69    let pptx_data = create_pptx_with_content("Text Formatting", slides)?;
70    fs::write("examples/output/text_formatting.pptx", pptx_data)?;
71    Ok(())
72}
73
74fn create_shapes_example() -> Result<(), Box<dyn std::error::Error>> {
75    let slides = vec![
76        SlideContent::new("Shape Types")
77            .add_bullet("Rectangle - basic rectangular shape")
78            .add_bullet("Circle - round elliptical shape")
79            .add_bullet("Triangle - three-sided polygon")
80            .add_bullet("Diamond - rotated square")
81            .add_bullet("Arrow - directional indicator")
82            .add_bullet("Star - five-pointed star")
83            .add_bullet("Hexagon - six-sided polygon"),
84        SlideContent::new("Shape Properties")
85            .add_bullet("Fill colors - solid color fills")
86            .add_bullet("Transparency - adjustable opacity")
87            .add_bullet("Borders - customizable lines")
88            .add_bullet("Text - add text inside shapes")
89            .add_bullet("Positioning - precise placement")
90            .add_bullet("Sizing - flexible dimensions"),
91        SlideContent::new("Shape Examples")
92            .add_bullet("Rectangle: 2x1 inch blue box")
93            .add_bullet("Circle: 1 inch red circle")
94            .add_bullet("Triangle: green triangle with border")
95            .add_bullet("Diamond: yellow diamond with text")
96            .add_bullet("Arrow: orange arrow pointing right"),
97    ];
98
99    let pptx_data = create_pptx_with_content("Shape Demonstrations", slides)?;
100    fs::write("examples/output/shapes_demo.pptx", pptx_data)?;
101    Ok(())
102}
103
104fn create_tables_example() -> Result<(), Box<dyn std::error::Error>> {
105    let slides = vec![
106        SlideContent::new("Table Basics")
107            .add_bullet("Tables organize data in rows and columns")
108            .add_bullet("Headers can be formatted differently")
109            .add_bullet("Cells can have background colors")
110            .add_bullet("Text can be bold or styled")
111            .add_bullet("Column widths are customizable"),
112        SlideContent::new("Sales Data Example")
113            .add_bullet("Q1 2025: $2.5M revenue")
114            .add_bullet("Q2 2025: $3.1M revenue")
115            .add_bullet("Q3 2025: $3.8M revenue")
116            .add_bullet("Q4 2025: $4.2M revenue (projected)")
117            .add_bullet("Total: $13.6M annual revenue"),
118        SlideContent::new("Team Members")
119            .add_bullet("Alice Johnson - Engineering Lead")
120            .add_bullet("Bob Smith - Product Manager")
121            .add_bullet("Carol Davis - Design Lead")
122            .add_bullet("David Wilson - Marketing Manager")
123            .add_bullet("Eve Martinez - Operations"),
124    ];
125
126    let pptx_data = create_pptx_with_content("Table Examples", slides)?;
127    fs::write("examples/output/tables_demo.pptx", pptx_data)?;
128    Ok(())
129}