-
-
Save Remo/f65e8fc3810bfa064f0cef5b04a1fac9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* composer.json: | |
* | |
* { | |
* "name": "ortic/aspose-test", | |
* "description": "Aspose Test project.", | |
* "keywords": ["aspose", "test"], | |
* "license": "MIT", | |
* "type": "project", | |
* "repositories": [ | |
* { | |
* "type": "vcs", | |
* "url": "git@gitlab.com:aspose/storage-sdk-php.git" | |
* } | |
* ], | |
* "require": { | |
* "aspose/slides-sdk-php": "dev-master" | |
* } | |
* } | |
*/ | |
require 'vendor/autoload.php'; | |
use Aspose\Slides\SlidesApi; | |
use Aspose\Slides\AsposeApp; | |
use Aspose\Storage\APIClient; | |
use Aspose\Storage\StorageApi; | |
// custom API method to support arbitrary parameters | |
function GetSlideWithFormat(&$apiClient, $name, $slideIndex, $format, $width = null, $height = null, $folder = null, $storage = null, $queryParams = []) | |
{ | |
// verify required params are set | |
if ($name == '' || $slideIndex == '' || $format == '') { | |
throw new Exception("missing required params"); | |
} | |
//parse inputs | |
$resourcePath = "/slides/{name}/slides/{slideIndex}/?appSid={appSid}&toFormat={toFormat}&width={width}&height={height}&folder={folder}&storage={storage}"; | |
//$resourcePath = str_replace("{format}", "json", $resourcePath); | |
$resourcePath = str_replace("toFormat={toFormat}", "format={format}", str_replace("/?", "?", str_replace("&", "&", str_replace("\\*", "", $resourcePath)))); | |
$method = "GET"; | |
$headerParams = array(); | |
$headerParams['Accept'] = 'application/xml,application/octet-stream'; | |
$headerParams['Content-Type'] = 'application/json'; | |
if ($name != null) { | |
$resourcePath = str_replace("{" . "name" . "}", $apiClient->toQueryValue($name), $resourcePath); | |
} else { | |
$resourcePath = str_replace("&name={" . "name" . "}", "", $resourcePath); | |
} | |
if ($slideIndex != null) { | |
$resourcePath = str_replace("{" . "slideIndex" . "}", $apiClient->toQueryValue($slideIndex), $resourcePath); | |
} else { | |
$resourcePath = str_replace("&slideIndex={" . "slideIndex" . "}", "", $resourcePath); | |
} | |
if ($format != null) { | |
$resourcePath = str_replace("{" . "format" . "}", $apiClient->toQueryValue($format), $resourcePath); | |
} else { | |
$resourcePath = str_replace("&format={" . "format" . "}", "", $resourcePath); | |
} | |
if ($width != null) { | |
$resourcePath = str_replace("{" . "width" . "}", $apiClient->toQueryValue($width), $resourcePath); | |
} else { | |
$resourcePath = str_replace("&width={" . "width" . "}", "", $resourcePath); | |
} | |
if ($height != null) { | |
$resourcePath = str_replace("{" . "height" . "}", $apiClient->toQueryValue($height), $resourcePath); | |
} else { | |
$resourcePath = str_replace("&height={" . "height" . "}", "", $resourcePath); | |
} | |
if ($folder != null) { | |
$resourcePath = str_replace("{" . "folder" . "}", $apiClient->toQueryValue($folder), $resourcePath); | |
} else { | |
$resourcePath = str_replace("&folder={" . "folder" . "}", "", $resourcePath); | |
} | |
if ($storage != null) { | |
$resourcePath = str_replace("{" . "storage" . "}", $apiClient->toQueryValue($storage), $resourcePath); | |
} else { | |
$resourcePath = str_replace("&storage={" . "storage" . "}", "", $resourcePath); | |
} | |
//make the API Call | |
if (!isset($body)) { | |
$body = null; | |
} | |
if (isset($file)) { | |
$body = $file; | |
} | |
$response = $apiClient->callAPI($resourcePath, $method, $queryParams, $body, $headerParams); | |
if (!$response) { | |
return null; | |
} | |
$responseObject = $apiClient->deserialize($response, 'ResponseMessage'); | |
return $responseObject; | |
} | |
// initialize aspose | |
AsposeApp::$appSID = 'APP_SID'; | |
AsposeApp::$apiKey = 'APP_KEY'; | |
$storage = new StorageApi(); | |
$apiClient = new APIClient(); | |
$apiClient->apiKey = AsposeApp::$apiKey; | |
$apiClient->appSid = AsposeApp::$appSID; | |
$storage->apiClient = $apiClient; | |
$slidesApi = new SlidesApi(); | |
// file names for testing | |
$localFileName = 'test.pptx'; | |
$storageFileName = 'test.pptx'; | |
$outputFilename = 'test.svg'; | |
// upload file | |
/* | |
$storage->PutCreate($storageFileName, null, null, $localFileName);*/ | |
// save slide as svg | |
$slideIndex = 1; | |
$format = 'svg'; | |
$result = GetSlideWithFormat($apiClient, $storageFileName, $slideIndex, $format, null, null, null, null, [ | |
'options' => [ | |
'PicturesCompression' => 'Dpi330', | |
'JpegQuality' => 90, | |
'DeletePicturesCroppedAreas' => true, | |
], | |
'fontsFolder' => 'fonts', | |
]); | |
$fh = fopen($outputFilename, 'wb'); | |
fwrite($fh, $result); | |
fclose($fh); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment