Skip to main content

PresentationBuilder

Struct PresentationBuilder 

Source
pub struct PresentationBuilder {
    pub title: String,
    pub slides: usize,
    pub config: Config,
}
Expand description

Complete PPTX presentation builder

Fields§

§title: String§slides: usize§config: Config

Implementations§

Source§

impl PresentationBuilder

Source

pub fn new(title: &str) -> Self

Create a new presentation builder

Examples found in repository?
examples/integrated_example.rs (line 20)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    println!("╔════════════════════════════════════════════════════════════╗");
12    println!("║     Integrated PPTX Generation Example                    ║");
13    println!("╚════════════════════════════════════════════════════════════╝\n");
14
15    // Create output directory
16    fs::create_dir_all("examples/output")?;
17
18    // Example 1: Using PresentationBuilder
19    println!("1. Creating presentation with PresentationBuilder...");
20    let builder = PresentationBuilder::new("Integrated Example")
21        .with_slides(5);
22    builder.save_to_file("examples/output/integrated_example.pptx")?;
23    println!("   ✓ Created: examples/output/integrated_example.pptx\n");
24
25    // Example 2: Using metadata
26    println!("2. Creating presentation with metadata...");
27    let metadata = PresentationMetadata::new("Business Report", 8);
28    println!("   Title: {}", metadata.title);
29    println!("   Slides: {}", metadata.slides);
30    println!("   Created: {}", metadata.created);
31    println!("   Modified: {}\n", metadata.modified);
32
33    let builder = PresentationBuilder::new(&metadata.title)
34        .with_slides(metadata.slides);
35    builder.save_to_file("examples/output/business_report.pptx")?;
36    println!("   ✓ Created: examples/output/business_report.pptx\n");
37
38    // Example 3: Using slide builder
39    println!("3. Creating slides with SlideBuilder...");
40    let slide1 = SlideBuilder::new("Introduction")
41        .with_content("Welcome to the presentation");
42    let (title1, content1) = slide1.build();
43    println!("   Slide 1: {} - {}", title1, content1);
44
45    let slide2 = SlideBuilder::new("Main Content")
46        .with_content("Key points and details");
47    let (title2, content2) = slide2.build();
48    println!("   Slide 2: {} - {}\n", title2, content2);
49
50    // Example 4: Using utility functions
51    println!("4. Using utility functions...");
52    let inches = utils::inches_to_emu(1.0);
53    println!("   1 inch = {} EMU", inches);
54
55    let cm = utils::cm_to_emu(2.54);
56    println!("   2.54 cm = {} EMU", cm);
57
58    let pt = utils::pt_to_emu(12.0);
59    println!("   12 pt = {} EMU\n", pt);
60
61    // Example 5: File size formatting
62    println!("5. File size formatting...");
63    println!("   {} bytes = {}", 512, utils::format_size(512));
64    println!("   {} bytes = {}", 5637, utils::format_size(5637));
65    println!("   {} bytes = {}\n", 1024 * 1024, utils::format_size(1024 * 1024));
66
67    // Example 6: Using enumerations
68    println!("6. Using enumeration types...");
69    println!("   Action: {}", enums::action::PpActionType::HYPERLINK);
70    println!("   Chart: {}", enums::chart::XlChartType::COLUMN_CLUSTERED);
71    println!("   Shape: {}", enums::shapes::MsoShapeType::AUTO_SHAPE);
72    println!("   Text: {}", enums::text::PpParagraphAlignment::CENTER);
73    println!("   Language: {}", enums::lang::MsoLanguageID::ENGLISH_US);
74
75    // Example 7: Verify generated files
76    println!("\n7. Verifying generated files...");
77    for file in &[
78        "examples/output/integrated_example.pptx",
79        "examples/output/business_report.pptx",
80    ] {
81        if let Ok(metadata) = fs::metadata(file) {
82            let size = utils::format_size(metadata.len() as usize);
83            println!("   ✓ {} ({})", file, size);
84        }
85    }
86
87    println!("\n✅ Integrated example completed successfully!");
88    println!("\nKey features demonstrated:");
89    println!("  • PresentationBuilder for easy creation");
90    println!("  • SlideBuilder for slide management");
91    println!("  • PresentationMetadata for tracking");
92    println!("  • Utility functions for conversions");
93    println!("  • Enumeration types for type safety");
94    println!("  • File size formatting");
95    println!("  • Error handling with Result types");
96
97    Ok(())
98}
Source

pub fn with_config(self, config: Config) -> Self

Create with custom config

Source

pub fn with_slides(self, count: usize) -> Self

Set number of slides

Examples found in repository?
examples/integrated_example.rs (line 21)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    println!("╔════════════════════════════════════════════════════════════╗");
12    println!("║     Integrated PPTX Generation Example                    ║");
13    println!("╚════════════════════════════════════════════════════════════╝\n");
14
15    // Create output directory
16    fs::create_dir_all("examples/output")?;
17
18    // Example 1: Using PresentationBuilder
19    println!("1. Creating presentation with PresentationBuilder...");
20    let builder = PresentationBuilder::new("Integrated Example")
21        .with_slides(5);
22    builder.save_to_file("examples/output/integrated_example.pptx")?;
23    println!("   ✓ Created: examples/output/integrated_example.pptx\n");
24
25    // Example 2: Using metadata
26    println!("2. Creating presentation with metadata...");
27    let metadata = PresentationMetadata::new("Business Report", 8);
28    println!("   Title: {}", metadata.title);
29    println!("   Slides: {}", metadata.slides);
30    println!("   Created: {}", metadata.created);
31    println!("   Modified: {}\n", metadata.modified);
32
33    let builder = PresentationBuilder::new(&metadata.title)
34        .with_slides(metadata.slides);
35    builder.save_to_file("examples/output/business_report.pptx")?;
36    println!("   ✓ Created: examples/output/business_report.pptx\n");
37
38    // Example 3: Using slide builder
39    println!("3. Creating slides with SlideBuilder...");
40    let slide1 = SlideBuilder::new("Introduction")
41        .with_content("Welcome to the presentation");
42    let (title1, content1) = slide1.build();
43    println!("   Slide 1: {} - {}", title1, content1);
44
45    let slide2 = SlideBuilder::new("Main Content")
46        .with_content("Key points and details");
47    let (title2, content2) = slide2.build();
48    println!("   Slide 2: {} - {}\n", title2, content2);
49
50    // Example 4: Using utility functions
51    println!("4. Using utility functions...");
52    let inches = utils::inches_to_emu(1.0);
53    println!("   1 inch = {} EMU", inches);
54
55    let cm = utils::cm_to_emu(2.54);
56    println!("   2.54 cm = {} EMU", cm);
57
58    let pt = utils::pt_to_emu(12.0);
59    println!("   12 pt = {} EMU\n", pt);
60
61    // Example 5: File size formatting
62    println!("5. File size formatting...");
63    println!("   {} bytes = {}", 512, utils::format_size(512));
64    println!("   {} bytes = {}", 5637, utils::format_size(5637));
65    println!("   {} bytes = {}\n", 1024 * 1024, utils::format_size(1024 * 1024));
66
67    // Example 6: Using enumerations
68    println!("6. Using enumeration types...");
69    println!("   Action: {}", enums::action::PpActionType::HYPERLINK);
70    println!("   Chart: {}", enums::chart::XlChartType::COLUMN_CLUSTERED);
71    println!("   Shape: {}", enums::shapes::MsoShapeType::AUTO_SHAPE);
72    println!("   Text: {}", enums::text::PpParagraphAlignment::CENTER);
73    println!("   Language: {}", enums::lang::MsoLanguageID::ENGLISH_US);
74
75    // Example 7: Verify generated files
76    println!("\n7. Verifying generated files...");
77    for file in &[
78        "examples/output/integrated_example.pptx",
79        "examples/output/business_report.pptx",
80    ] {
81        if let Ok(metadata) = fs::metadata(file) {
82            let size = utils::format_size(metadata.len() as usize);
83            println!("   ✓ {} ({})", file, size);
84        }
85    }
86
87    println!("\n✅ Integrated example completed successfully!");
88    println!("\nKey features demonstrated:");
89    println!("  • PresentationBuilder for easy creation");
90    println!("  • SlideBuilder for slide management");
91    println!("  • PresentationMetadata for tracking");
92    println!("  • Utility functions for conversions");
93    println!("  • Enumeration types for type safety");
94    println!("  • File size formatting");
95    println!("  • Error handling with Result types");
96
97    Ok(())
98}
Source

pub fn build(&self) -> Result<Vec<u8>>

Build and generate PPTX file

Source

pub fn save_to_file(&self, path: &str) -> Result<()>

Save to file

Examples found in repository?
examples/integrated_example.rs (line 22)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    println!("╔════════════════════════════════════════════════════════════╗");
12    println!("║     Integrated PPTX Generation Example                    ║");
13    println!("╚════════════════════════════════════════════════════════════╝\n");
14
15    // Create output directory
16    fs::create_dir_all("examples/output")?;
17
18    // Example 1: Using PresentationBuilder
19    println!("1. Creating presentation with PresentationBuilder...");
20    let builder = PresentationBuilder::new("Integrated Example")
21        .with_slides(5);
22    builder.save_to_file("examples/output/integrated_example.pptx")?;
23    println!("   ✓ Created: examples/output/integrated_example.pptx\n");
24
25    // Example 2: Using metadata
26    println!("2. Creating presentation with metadata...");
27    let metadata = PresentationMetadata::new("Business Report", 8);
28    println!("   Title: {}", metadata.title);
29    println!("   Slides: {}", metadata.slides);
30    println!("   Created: {}", metadata.created);
31    println!("   Modified: {}\n", metadata.modified);
32
33    let builder = PresentationBuilder::new(&metadata.title)
34        .with_slides(metadata.slides);
35    builder.save_to_file("examples/output/business_report.pptx")?;
36    println!("   ✓ Created: examples/output/business_report.pptx\n");
37
38    // Example 3: Using slide builder
39    println!("3. Creating slides with SlideBuilder...");
40    let slide1 = SlideBuilder::new("Introduction")
41        .with_content("Welcome to the presentation");
42    let (title1, content1) = slide1.build();
43    println!("   Slide 1: {} - {}", title1, content1);
44
45    let slide2 = SlideBuilder::new("Main Content")
46        .with_content("Key points and details");
47    let (title2, content2) = slide2.build();
48    println!("   Slide 2: {} - {}\n", title2, content2);
49
50    // Example 4: Using utility functions
51    println!("4. Using utility functions...");
52    let inches = utils::inches_to_emu(1.0);
53    println!("   1 inch = {} EMU", inches);
54
55    let cm = utils::cm_to_emu(2.54);
56    println!("   2.54 cm = {} EMU", cm);
57
58    let pt = utils::pt_to_emu(12.0);
59    println!("   12 pt = {} EMU\n", pt);
60
61    // Example 5: File size formatting
62    println!("5. File size formatting...");
63    println!("   {} bytes = {}", 512, utils::format_size(512));
64    println!("   {} bytes = {}", 5637, utils::format_size(5637));
65    println!("   {} bytes = {}\n", 1024 * 1024, utils::format_size(1024 * 1024));
66
67    // Example 6: Using enumerations
68    println!("6. Using enumeration types...");
69    println!("   Action: {}", enums::action::PpActionType::HYPERLINK);
70    println!("   Chart: {}", enums::chart::XlChartType::COLUMN_CLUSTERED);
71    println!("   Shape: {}", enums::shapes::MsoShapeType::AUTO_SHAPE);
72    println!("   Text: {}", enums::text::PpParagraphAlignment::CENTER);
73    println!("   Language: {}", enums::lang::MsoLanguageID::ENGLISH_US);
74
75    // Example 7: Verify generated files
76    println!("\n7. Verifying generated files...");
77    for file in &[
78        "examples/output/integrated_example.pptx",
79        "examples/output/business_report.pptx",
80    ] {
81        if let Ok(metadata) = fs::metadata(file) {
82            let size = utils::format_size(metadata.len() as usize);
83            println!("   ✓ {} ({})", file, size);
84        }
85    }
86
87    println!("\n✅ Integrated example completed successfully!");
88    println!("\nKey features demonstrated:");
89    println!("  • PresentationBuilder for easy creation");
90    println!("  • SlideBuilder for slide management");
91    println!("  • PresentationMetadata for tracking");
92    println!("  • Utility functions for conversions");
93    println!("  • Enumeration types for type safety");
94    println!("  • File size formatting");
95    println!("  • Error handling with Result types");
96
97    Ok(())
98}
Source

pub fn save(&self, filename: &str) -> Result<()>

Save to configured output directory

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more