web2ppt_demo/
web2ppt_demo.rs1#[cfg(feature = "web2ppt")]
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 use ppt_rs::{
8 html_to_pptx, html_to_pptx_with_options,
9 Web2PptConfig, ConversionOptions,
10 };
11
12 println!("=== Web2PPT Demo ===\n");
13
14 println!("📄 Example 1: HTML to PPTX");
16
17 let html = r#"
18 <!DOCTYPE html>
19 <html>
20 <head>
21 <title>Rust Programming Language</title>
22 <meta name="description" content="A systems programming language focused on safety and performance">
23 </head>
24 <body>
25 <main>
26 <h1>Rust Programming Language</h1>
27 <p>Rust is a multi-paradigm, general-purpose programming language that emphasizes performance, type safety, and concurrency.</p>
28
29 <h2>Key Features</h2>
30 <ul>
31 <li>Memory safety without garbage collection</li>
32 <li>Concurrency without data races</li>
33 <li>Zero-cost abstractions</li>
34 <li>Minimal runtime</li>
35 <li>Efficient C bindings</li>
36 </ul>
37
38 <h2>Getting Started</h2>
39 <p>Install Rust using rustup, the official Rust toolchain installer. It manages Rust versions and associated tools.</p>
40
41 <pre><code>curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh</code></pre>
42
43 <h2>Hello World</h2>
44 <p>Create your first Rust program with a simple hello world example that demonstrates the basic syntax.</p>
45
46 <pre><code>fn main() {
47 println!("Hello, world!");
48}</code></pre>
49
50 <h2>Cargo</h2>
51 <p>Cargo is Rust's build system and package manager. It handles downloading dependencies, compiling code, and more.</p>
52 <ul>
53 <li>cargo new - Create a new project</li>
54 <li>cargo build - Build your project</li>
55 <li>cargo run - Run your project</li>
56 <li>cargo test - Run tests</li>
57 </ul>
58
59 <h2>Community</h2>
60 <p>Rust has a welcoming and helpful community. Join the official forums, Discord, or Reddit to connect with other Rustaceans.</p>
61 </main>
62 </body>
63 </html>
64 "#;
65
66 let pptx = html_to_pptx(html, "https://rust-lang.org")?;
67 std::fs::create_dir_all("examples/output")?;
68 std::fs::write("examples/output/rust_intro.pptx", &pptx)?;
69 println!(" ✅ Created rust_intro.pptx ({} bytes)\n", pptx.len());
70
71 println!("📄 Example 2: Custom options");
73
74 let config = Web2PptConfig::new()
75 .max_slides(5)
76 .max_bullets(4)
77 .with_code(true);
78
79 let options = ConversionOptions::new()
80 .title("Rust Quick Start")
81 .author("ppt-rs")
82 .with_source_url(true);
83
84 let pptx = html_to_pptx_with_options(html, "https://rust-lang.org", config, options)?;
85 std::fs::write("examples/output/rust_quick.pptx", &pptx)?;
86 println!(" ✅ Created rust_quick.pptx ({} bytes)\n", pptx.len());
87
88 println!("📄 Example 3: Technical documentation");
90
91 let tech_html = r#"
92 <!DOCTYPE html>
93 <html>
94 <head><title>API Documentation</title></head>
95 <body>
96 <main>
97 <h1>REST API Reference</h1>
98 <p>This document describes the REST API endpoints available for integration with our platform.</p>
99
100 <h2>Authentication</h2>
101 <p>All API requests require authentication using Bearer tokens in the Authorization header.</p>
102 <pre><code>Authorization: Bearer YOUR_API_KEY</code></pre>
103
104 <h2>Endpoints</h2>
105
106 <h3>GET /users</h3>
107 <p>Retrieve a list of all users in the system with pagination support.</p>
108 <ul>
109 <li>page - Page number (default: 1)</li>
110 <li>limit - Items per page (default: 20)</li>
111 <li>sort - Sort field (name, email, created_at)</li>
112 </ul>
113
114 <h3>POST /users</h3>
115 <p>Create a new user account with the specified details and permissions.</p>
116 <pre><code>{
117 "name": "John Doe",
118 "email": "john@example.com",
119 "role": "user"
120}</code></pre>
121
122 <h3>GET /users/{id}</h3>
123 <p>Retrieve details for a specific user by their unique identifier.</p>
124
125 <h2>Error Handling</h2>
126 <p>The API uses standard HTTP status codes to indicate success or failure of requests.</p>
127 <ul>
128 <li>200 - Success</li>
129 <li>400 - Bad Request</li>
130 <li>401 - Unauthorized</li>
131 <li>404 - Not Found</li>
132 <li>500 - Server Error</li>
133 </ul>
134
135 <h2>Rate Limiting</h2>
136 <p>API requests are limited to 100 requests per minute per API key to ensure fair usage.</p>
137 </main>
138 </body>
139 </html>
140 "#;
141
142 let pptx = html_to_pptx(tech_html, "https://api.example.com/docs")?;
143 std::fs::write("examples/output/api_docs.pptx", &pptx)?;
144 println!(" ✅ Created api_docs.pptx ({} bytes)\n", pptx.len());
145
146 println!("=== Demo Complete ===");
147 println!("\nGenerated files in examples/output/:");
148 println!(" - rust_intro.pptx");
149 println!(" - rust_quick.pptx");
150 println!(" - api_docs.pptx");
151
152 Ok(())
153}
154
155#[cfg(not(feature = "web2ppt"))]
156fn main() {
157 eprintln!("❌ This example requires the 'web2ppt' feature.");
158 eprintln!(" Run with: cargo run --example web2ppt_demo --features web2ppt");
159}