hello_world_pptx/
hello_world_pptx.rs1use std::path::{Path, PathBuf};
8
9use office_toolkit::drawing::{ShapeProperties, TextBody, TextParagraph, TextRun, Transform2D};
10use office_toolkit::powerpoint::{AutoShape, Shape};
11use office_toolkit::prelude::*;
12use office_toolkit::{OpenFile, SaveToFile};
13
14fn main() -> office_toolkit::Result<()> {
15 let path = output_path("hello_world.pptx");
16
17 let text_box = AutoShape::new(2, "Hello box")
18 .with_properties(
19 ShapeProperties::new().with_transform(
20 Transform2D::new()
21 .with_offset(838_200, 1_365_250)
22 .with_extent(7_772_400, 1_200_150),
23 ),
24 )
25 .with_text_body(
26 TextBody::new()
27 .with_paragraph(TextParagraph::new().with_run(TextRun::text("Hello, world!"))),
28 );
29
30 let presentation =
32 Presentation::new().with_slide(Slide::new().with_shape(Shape::AutoShape(text_box)));
33 presentation.save_to_file(&path)?;
34 println!("Wrote {}", path.display());
35
36 let reopened = Presentation::open_file(&path)?;
38 println!("Slide count: {}", reopened.slides.len());
39
40 Ok(())
41}
42
43fn output_path(filename: &str) -> PathBuf {
47 Path::new(env!("CARGO_MANIFEST_DIR"))
48 .join("../../tests-data/output")
49 .join(filename)
50}