A PHP SDK for the PowerPoint Engine API that allows you to generate, modify, and manipulate PowerPoint presentations programmatically.
- 🚀 Simple & Intuitive: Easy-to-use PHP interface
- 📊 Rich Data Support: Charts, tables, images, and text
- 🎨 Template Processing: Work with custom PowerPoint templates
- 🔐 Secure: Built-in API key management
- 📝 Modern PHP: PHP 8.0+ with type declarations
- ⚡ PSR Compliant: Follows PSR-4, PSR-7, PSR-18 standards
- 🧪 Well Tested: Comprehensive test suite included
composer require powerpoint-engine-api/powerpoint-engine-php
<?php
require_once 'vendor/autoload.php';
use PowerPointEngine\Client;
use PowerPointEngine\Exception\PowerPointEngineException;
// Initialize the client
$client = new Client('your_api_key_here');
try {
// Generate a simple presentation
$presentation = $client->presentations()->create([
'template' => 'business-report',
'data' => [
'title' => 'Q4 Business Report',
'slides' => [
[
'type' => 'title',
'title' => 'Sales Performance',
'subtitle' => 'Outstanding results this quarter'
],
[
'type' => 'chart',
'title' => 'Revenue Growth',
'chart_type' => 'bar',
'chart_data' => [
'labels' => ['Jan', 'Feb', 'Mar'],
'datasets' => [
[
'label' => 'Revenue',
'values' => [100, 150, 200]
]
]
]
]
]
]
]);
// Download the presentation
$fileContent = $presentation->download();
file_put_contents('report.pptx', $fileContent);
echo "Presentation created: " . $presentation->getId() . "\n";
} catch (PowerPointEngineException $e) {
echo "Error: " . $e->getMessage() . "\n";
echo "Status Code: " . $e->getStatusCode() . "\n";
echo "Request ID: " . $e->getRequestId() . "\n";
}
use PowerPointEngine\Client;
// Basic initialization
$client = new Client('your_api_key');
// With custom configuration
$client = new Client('your_api_key', [
'base_url' => 'https://api.powerpointengine.io',
'timeout' => 30,
'max_retries' => 3
]);
// From template
$presentation = $client->presentations()->create([
'template' => 'business-report',
'data' => [
'title' => 'My Presentation',
'slides' => [...]
]
]);
// From scratch
$presentation = $client->presentations()->create([
'slides' => [
[
'type' => 'title',
'title' => 'Welcome',
'subtitle' => 'Getting Started'
]
]
]);
$presentation = $client->presentations()->get('presentation_id');
echo "Status: " . $presentation->getStatus() . "\n";
echo "Created: " . $presentation->getCreatedAt() . "\n";
$presentations = $client->presentations()->list([
'limit' => 10,
'offset' => 0,
'status' => 'completed'
]);
foreach ($presentations->getData() as $presentation) {
echo $presentation->getId() . ": " . $presentation->getStatus() . "\n";
}
// Download as string
$content = $presentation->download();
// Save to file
file_put_contents('presentation.pptx', $content);
// Or use the convenience method
$presentation->saveToFile('presentation.pptx');
$templates = $client->templates()->list();
foreach ($templates->getData() as $template) {
echo $template->getId() . ": " . $template->getName() . "\n";
}
$template = $client->templates()->get('business-report');
echo "Description: " . $template->getDescription() . "\n";
echo "Placeholders: " . implode(', ', $template->getPlaceholders()) . "\n";
$fileContent = file_get_contents('my_template.pptx');
$template = $client->templates()->upload([
'file' => $fileContent,
'name' => 'custom-template',
'description' => 'My custom template'
]);
// Title slide
[
'type' => 'title',
'title' => 'Presentation Title',
'subtitle' => 'Subtitle text'
]
// Content slide
[
'type' => 'content',
'title' => 'Slide Title',
'content' => 'Slide content text'
]
// Chart slide
[
'type' => 'chart',
'title' => 'Chart Title',
'chart_type' => 'bar', // bar, line, pie, column
'chart_data' => [
'labels' => ['A', 'B', 'C'],
'datasets' => [
[
'label' => 'Series 1',
'values' => [10, 20, 30]
]
]
]
]
// Table slide
[
'type' => 'table',
'title' => 'Table Title',
'table_data' => [
'headers' => ['Name', 'Value', 'Change'],
'rows' => [
['Product A', '100', '+5%'],
['Product B', '200', '+10%']
]
]
]
// Image slide
[
'type' => 'image',
'title' => 'Image Title',
'image_url' => 'https://example.com/image.jpg',
'caption' => 'Image caption'
]
use PowerPointEngine\Client;
use PowerPointEngine\Exception\AuthenticationException;
use PowerPointEngine\Exception\ValidationException;
use PowerPointEngine\Exception\NotFoundmentException;
use PowerPointEngine\Exception\RateLimitException;
use PowerPointEngine\Exception\ServerException;
try {
$client = new Client('invalid_key');
$presentation = $client->presentations()->create(['slides' => []]);
} catch (AuthenticationException $e) {
echo "Authentication failed: " . $e->getMessage() . "\n";
} catch (ValidationException $e) {
echo "Validation error: " . $e->getMessage() . "\n";
} catch (NotFoundmentException $e) {
echo "Resource not found: " . $e->getMessage() . "\n";
} catch (RateLimitException $e) {
echo "Rate limit exceeded: " . $e->getMessage() . "\n";
} catch (ServerException $e) {
echo "Server error: " . $e->getMessage() . "\n";
}
// Configure webhook for presentation completion
$webhook = $client->webhooks()->create([
'url' => 'https://yourapp.com/webhook',
'events' => ['presentation.completed', 'presentation.failed']
]);
// List webhooks
$webhooks = $client->webhooks()->list();
// Delete webhook
$client->webhooks()->delete($webhook->getId());
// config/services.php
'powerpoint_engine' => [
'api_key' => env('POWERPOINT_ENGINE_API_KEY'),
],
// Service Provider
use PowerPointEngine\Client;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(Client::class, function ($app) {
return new Client(config('services.powerpoint_engine.api_key'));
});
}
}
// Usage in Controller
class PresentationController extends Controller
{
public function __construct(private Client $powerpointEngine)
{
}
public function generateReport(Request $request)
{
$presentation = $this->powerpointEngine->presentations()->create([
'template' => 'business-report',
'data' => $request->validated()
]);
return response()->json([
'presentation_id' => $presentation->getId(),
'status' => $presentation->getStatus()
]);
}
}
# config/services.yaml
services:
PowerPointEngine\Client:
arguments:
$apiKey: '%env(POWERPOINT_ENGINE_API_KEY)%'
// Controller
use PowerPointEngine\Client;
use Symfony\Component\HttpFoundation\Response;
class PresentationController extends AbstractController
{
public function __construct(private Client $powerpointEngine)
{
}
#[Route('/generate-presentation', methods: ['POST'])]
public function generate(Request $request): Response
{
$data = json_decode($request->getContent(), true);
$presentation = $this->powerpointEngine->presentations()->create($data);
return $this->json([
'presentation_id' => $presentation->getId(),
'status' => $presentation->getStatus()
]);
}
}
Check out the examples directory for more detailed examples:
- Basic presentation generation
- Working with templates
- Charts and data visualization
- Batch processing
- Laravel integration
- Symfony integration
- PHP 8.0 or higher
- ext-curl
- ext-json
- ext-mbstring
- ✅ Laravel 9.0+
- ✅ Symfony 6.0+
- ✅ CodeIgniter 4.0+
- ✅ CakePHP 4.0+
- ✅ Laminas/Zend Framework
- ✅ Vanilla PHP
We welcome contributions! Please see our Contributing Guide for details.
This SDK is released under the MIT License. See LICENSE for details.
See CHANGELOG.md for version history and updates.