PHP code example of groupdocscloud / viewer-sdk-php
1. Go to this page and download the library: Download groupdocscloud/viewer-sdk-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
groupdocscloud / viewer-sdk-php example snippets
t your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is -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";
}
iguration = 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";
}
php composer.phar install
./vendor/bin/phpunit
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.