This repository contains GroupDocs.Viewer Cloud SDK for PHP source code. This SDK allows you to work with GroupDocs.Viewer Cloud REST APIs in your PHP applications.
- PHP 5.5 or later
To use SDK you need AppSID and AppKey authorization keys. You can get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
The package is available at Packagist and it can be installed via Composer by executing following command:
composer require groupdocscloud/groupdocs-viewer-cloud
Or you can install SDK via Composer directly from this repository, add the following to composer.json
:
{
"repositories": [
{
"type": "git",
"url": "https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-php.git"
}
],
"require": {
"groupdocscloud/groupdocs-viewer-cloud": "*"
}
}
Then run composer install
Clone or download this repository, then run composer install
in the root directory to install dependencies and include autoload.php
into your code file:
require_once('/path/to/groupdocs-viewer-cloud-php/vendor/autoload.php');
To run the unit tests set your AppSID and AppKey in json.config and execute following commands:
php composer.phar install
./vendor/bin/phpunit
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
$configuration->setAppKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
$viewApi = new GroupDocs\Viewer\ViewApi($configuration);
try {
// Convert and download a document as JPG
$format = "jpg";
$filePath = "myfile.docx";
$request = new GroupDocs\Viewer\Model\Requests\convertAndDownloadRequest($format, $filePath);
$result = $viewApi->convertAndDownload($request);
// Save the resulting file
$outputPath = __DIR__ . "/output.jpg";
file_put_contents($outputPath, $result->fread($result->getSize()));
echo "File converted and saved to: " . $outputPath . "\n";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
Below is an example demonstrating how to upload a document, render it, and download the result using GroupDocs.Viewer Cloud SDK for PHP.
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$configuration = new GroupDocs\Viewer\Configuration();
$configuration->setAppSid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
$configuration->setAppKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
$fileApi = new GroupDocs\Viewer\FileApi($configuration);
$viewApi = new GroupDocs\Viewer\ViewApi($configuration);
try {
// Upload a file to cloud storage
$uploadRequest = new GroupDocs\Viewer\Model\Requests\uploadFileRequest("myfile.docx", __DIR__ . "/myfile.docx");
$fileApi->uploadFile($uploadRequest);
// Render it to HTML
$viewOptions = new GroupDocs\Viewer\Model\ViewOptions();
$fileInfo = new GroupDocs\Viewer\Model\FileInfo();
$fileInfo->setFilePath("myfile.docx");
$viewOptions->setFileInfo($fileInfo);
$viewOptions->setViewFormat("HTML");
$viewOptions->setOutputPath("myfile.html");
$viewRequest = new GroupDocs\Viewer\Model\Requests\createViewRequest($viewOptions);
$viewApi->createView($viewRequest);
// Download the result
$downloadRequest = new GroupDocs\Viewer\Model\Requests\downloadFileRequest("myfile.html");
$result = $fileApi->downloadFile($downloadRequest);
// Save the resulting file
$outputPath = __DIR__ . "/myfile.html";
file_put_contents($outputPath, $result->fread($result->getSize()));
echo "Rendered file downloaded to: " . $outputPath . "\n";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
GroupDocs.Viewer Cloud SDK for PHP is licensed under MIT License.
Your feedback is very important to us. Please feel free to contact us using our Support Forums.