Skip to content

Instantly share code, notes, and snippets.

@Remo
Last active August 21, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Remo/f65e8fc3810bfa064f0cef5b04a1fac9 to your computer and use it in GitHub Desktop.
Save Remo/f65e8fc3810bfa064f0cef5b04a1fac9 to your computer and use it in GitHub Desktop.
<?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}&amp;toFormat={toFormat}&amp;width={width}&amp;height={height}&amp;folder={folder}&amp;storage={storage}";
//$resourcePath = str_replace("{format}", "json", $resourcePath);
$resourcePath = str_replace("toFormat={toFormat}", "format={format}", str_replace("/?", "?", str_replace("&amp;", "&", 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