Skip to content

Instantly share code, notes, and snippets.

@groupdocscloud
Last active January 12, 2020 17:10
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 groupdocscloud/288fe44b5603cd7966fa72f293e91b88 to your computer and use it in GitHub Desktop.
Save groupdocscloud/288fe44b5603cd7966fa72f293e91b88 to your computer and use it in GitHub Desktop.
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFileApiInstance();
$request = new GroupDocs\Editor\Model\Requests\CopyFileRequest("Editordocs\one-page.docx", "Editordocs\one-page-copied.docx", CommonUtils::$MyStorage, CommonUtils::$MyStorage);
$apiInstance->copyFile($request);
echo "Expected response type is Void: 'Editordocs/one-page.docx' file copied as 'Editordocs/one-page-copied.docx'.";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFolderApiInstance();
$request = new GroupDocs\Editor\Model\Requests\CopyFolderRequest("Editordocs", "Editordocs1", CommonUtils::$MyStorage, CommonUtils::$MyStorage);
$apiInstance->copyFolder($request);
echo "Expected response type is Void: 'Editordocs' folder copied as 'Editordocs1'.", "<br />";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFolderApiInstance();
$request = new GroupDocs\Editor\Model\Requests\CreateFolderRequest("Editordocs", CommonUtils::$MyStorage);
$apiInstance->createFolder($request);
echo "Expected response type is Void: 'Editordocs' folder created.", "<br />";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFolderApiInstance();
$request = new GroupDocs\Editor\Model\Requests\DeleteFolderRequest("Editordocs1\\Editordocs1", CommonUtils::$MyStorage, true);
$apiInstance->deleteFolder($request);
echo "Expected response type is Void: 'Editordocs1/Editordocs1' folder deleted recursively.", "<br />";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFolderApiInstance();
$request = new GroupDocs\Editor\Model\Requests\DeleteFolderRequest("Editordocs1\\Editordocs1", CommonUtils::$MyStorage, true);
$apiInstance->deleteFolder($request);
echo "Expected response type is Void: 'Editordocs1/Editordocs1' folder deleted recursively.", "<br />";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFileApiInstance();
$request = new GroupDocs\Editor\Model\Requests\DownloadFileRequest("Editordocs\one-page.docx", CommonUtils::$MyStorage, null);
$response = $apiInstance->downloadFile($request);
echo "Expected response type is File: ", strlen($response);
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetStorageApiInstance();
$request = new GroupDocs\Editor\Model\Requests\GetDiscUsageRequest(CommonUtils::$MyStorage);
$response = $apiInstance->getDiscUsage($request);
echo "Expected response type is DiscUsage: ", $response;
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-php-samples
use GroupDocs\Editor\Model;
use GroupDocs\Editor\Model\Requests;
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Editor\Configuration();
$configuration->setAppSid($AppSid);
$configuration->setAppKey($AppKey);
$infoApi = new GroupDocs\Editor\InfoApi($configuration);
$response = $infoApi->getSupportedFileFormats();
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-php-samples
use GroupDocs\Editor\Model;
use GroupDocs\Editor\Model\Requests;
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Editor\Configuration();
$configuration->setAppSid($AppSid);
$configuration->setAppKey($AppKey);
$infoApi = new GroupDocs\Editor\InfoApi($configuration);
$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("WordProcessing/password-protected.docx");
$fileInfo->setPassword("password");
$response = $infoApi->getInfo(new Requests\getInfoRequest($fileInfo));
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetStorageApiInstance();
$request = new GroupDocs\Editor\Model\Requests\GetFileVersionsRequest("Editordocs\one-page.docx", CommonUtils::$MyStorage);
$response = $apiInstance->getFileVersions($request);
echo "Expected response type is FileVersions: ", $response;
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFolderApiInstance();
$request = new GroupDocs\Editor\Model\Requests\GetFilesListRequest("signaturedocs", CommonUtils::$MyStorage);
$response = $apiInstance->getFilesList($request);
echo "Expected response type is FilesList.", "<br />";
foreach($response->getValue() as $storageFile) {
echo "Files: ", $storageFile->getPath(), "<br />";
}
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFileApiInstance();
$request = new GroupDocs\Editor\Model\Requests\MoveFileRequest("Editordocs\one-page.docx", "Editordocs1\one-page-copied.docx", CommonUtils::$MyStorage, CommonUtils::$MyStorage);
$apiInstance->moveFile($request);
echo "Expected response type is Void: 'Editordocs/one-page.docx' file moved as 'Editordocs1/one-page-copied.docx'.";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFolderApiInstance();
$request = new GroupDocs\Editor\Model\Requests\MoveFolderRequest("Editordocs1", "Editordocs1\\Editordocs1", CommonUtils::$MyStorage, CommonUtils::$MyStorage, true);
$apiInstance->moveFolder($request);
echo "Expected response type is Void: 'Editordocs1' folder moved to 'Editordocs1/Editordocs1'.", "<br />";
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetStorageApiInstance();
$request = new GroupDocs\Editor\Model\Requests\ObjectExistsRequest("Editordocs\one-page.docx", CommonUtils::$MyStorage);
$response = $apiInstance->objectExists($request);
echo "Expected response type is ObjectExist: ", $response;
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetStorageApiInstance();
$request = new GroupDocs\Editor\Model\Requests\StorageExistsRequest(CommonUtils::$MyStorage);
$response = $apiInstance->storageExists($request);
echo "Expected response type is StorageExist: ", $response;
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
<?php
include(dirname(__DIR__) . '\CommonUtils.php');
try {
$apiInstance = CommonUtils::GetFileApiInstance();
$filePath = realpath(dirname(__DIR__). '\Resources\Editordocs\one-page.docx');
echo "filePath: ". $filePath;
$fileStream = readfile($filePath);
$request = new GroupDocs\Editor\Model\Requests\UploadFileRequest("Editordocs\one-page1.docx", $fileStream);
$response = $apiInstance->uploadFile($request);
echo "Expected response type is FilesUploadResult: ", $response;
} catch (Exception $e) {
echo "Something went wrong: ", $e->getMessage(), "\n";
}
?>
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-php-samples
use GroupDocs\Editor\Model;
use GroupDocs\Editor\Model\Requests;
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Editor\Configuration();
$configuration->setAppSid($AppSid);
$configuration->setAppKey($AppKey);
$editApi = new GroupDocs\Editor\EditApi($configuration);
$fileApi = new GroupDocs\Editor\FileApi($configuration);
// The document already uploaded into the storage
// Load it into editable state
$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("Spreadsheet/sample.tsv");
$loadOptions = new Model\DelimitedTextLoadOptions();
$loadOptions->setFileInfo($fileInfo);
$loadOptions->setOutputPath("output");
$loadResult = $editApi->load(new Requests\loadRequest($loadOptions));
// Download html document
$htmlFile = $fileApi->downloadFile(new Requests\downloadFileRequest($loadResult->getHtmlPath()));
$html = file_get_contents($htmlFile->getRealPath());
// Edit something...
$html = str_replace("32", "66", $html);
// Upload html back to storage
file_put_contents($htmlFile->getRealPath(), $html);
$uploadRequest = new Requests\uploadFileRequest($loadResult->getHtmlPath(), $htmlFile->getRealPath());
$fileApi->uploadFile($uploadRequest);
// Save html back to tsv
$saveOptions = new Model\DelimitedTextSaveOptions();
$saveOptions->setFileInfo($fileInfo);
$saveOptions->setOutputPath("output/edited.tsv");
$saveOptions->setHtmlPath($loadResult->getHtmlPath());
$saveOptions->setResourcesPath($loadResult->getResourcesPath());
$saveResult = $editApi->save(new Requests\saveRequest($saveOptions));
// Done.
echo "Document edited: " . $saveResult->getPath();
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-php-samples
use GroupDocs\Editor\Model;
use GroupDocs\Editor\Model\Requests;
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Editor\Configuration();
$configuration->setAppSid($AppSid);
$configuration->setAppKey($AppKey);
$editApi = new GroupDocs\Editor\EditApi($configuration);
$fileApi = new GroupDocs\Editor\FileApi($configuration);
// The document already uploaded into the storage
// Load it into editable state
$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("Presentation/with-notes.pptx");
$loadOptions = new Model\PresentationLoadOptions();
$loadOptions->setFileInfo($fileInfo);
$loadOptions->setOutputPath("output");
$loadOptions->setSlideNumber(0);
$loadResult = $editApi->load(new Requests\loadRequest($loadOptions));
// Download html document
$htmlFile = $fileApi->downloadFile(new Requests\downloadFileRequest($loadResult->getHtmlPath()));
$html = file_get_contents($htmlFile->getRealPath());
// Edit something...
$html = str_replace("Slide sub-heading", "Hello world!", $html);
// Upload html back to storage
file_put_contents($htmlFile->getRealPath(), $html);
$uploadRequest = new Requests\uploadFileRequest($loadResult->getHtmlPath(), $htmlFile->getRealPath());
$fileApi->uploadFile($uploadRequest);
// Save html back to pptx
$saveOptions = new Model\PresentationSaveOptions();
$saveOptions->setFileInfo($fileInfo);
$saveOptions->setOutputPath("output/edited.pptx");
$saveOptions->setHtmlPath($loadResult->getHtmlPath());
$saveOptions->setResourcesPath($loadResult->getResourcesPath());
$saveResult = $editApi->save(new Requests\saveRequest($saveOptions));
// Done.
echo "Document edited: " . $saveResult->getPath();
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-php-samples
use GroupDocs\Editor\Model;
use GroupDocs\Editor\Model\Requests;
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Editor\Configuration();
$configuration->setAppSid($AppSid);
$configuration->setAppKey($AppKey);
$editApi = new GroupDocs\Editor\EditApi($configuration);
$fileApi = new GroupDocs\Editor\FileApi($configuration);
// The document already uploaded into the storage
// Load it into editable state
$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("Spreadsheet/four-sheets.xlsx");
$loadOptions = new Model\SpreadsheetLoadOptions();
$loadOptions->setFileInfo($fileInfo);
$loadOptions->setOutputPath("output");
$loadOptions->setWorksheetIndex(0);
$loadResult = $editApi->load(new Requests\loadRequest($loadOptions));
// Download html document
$htmlFile = $fileApi->downloadFile(new Requests\downloadFileRequest($loadResult->getHtmlPath()));
$html = file_get_contents($htmlFile->getRealPath());
// Edit something...
$html = str_replace("This is sample sheet", "This is sample sheep", $html);
// Upload html back to storage
file_put_contents($htmlFile->getRealPath(), $html);
$uploadRequest = new Requests\uploadFileRequest($loadResult->getHtmlPath(), $htmlFile->getRealPath());
$fileApi->uploadFile($uploadRequest);
// Save html back to xlsx
$saveOptions = new Model\SpreadsheetSaveOptions();
$saveOptions->setFileInfo($fileInfo);
$saveOptions->setOutputPath("output/edited.xlsx");
$saveOptions->setHtmlPath($loadResult->getHtmlPath());
$saveOptions->setResourcesPath($loadResult->getResourcesPath());
$saveResult = $editApi->save(new Requests\saveRequest($saveOptions));
// Done.
echo "Document edited: " . $saveResult->getPath();
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-php-samples
use GroupDocs\Editor\Model;
use GroupDocs\Editor\Model\Requests;
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Editor\Configuration();
$configuration->setAppSid($AppSid);
$configuration->setAppKey($AppKey);
$editApi = new GroupDocs\Editor\EditApi($configuration);
$fileApi = new GroupDocs\Editor\FileApi($configuration);
// The document already uploaded into the storage
// Load it into editable state
$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("Text/document.txt");
$loadOptions = new Model\TextLoadOptions();
$loadOptions->setFileInfo($fileInfo);
$loadOptions->setOutputPath("output");
$loadResult = $editApi->load(new Requests\loadRequest($loadOptions));
// Download html document
$htmlFile = $fileApi->downloadFile(new Requests\downloadFileRequest($loadResult->getHtmlPath()));
$html = file_get_contents($htmlFile->getRealPath());
// Edit something...
$html = str_replace("Page Text", "New Text", $html);
// Upload html back to storage
file_put_contents($htmlFile->getRealPath(), $html);
$uploadRequest = new Requests\uploadFileRequest($loadResult->getHtmlPath(), $htmlFile->getRealPath());
$fileApi->uploadFile($uploadRequest);
// Save html back to txt
$saveOptions = new Model\TextSaveOptions();
$saveOptions->setFileInfo($fileInfo);
$saveOptions->setOutputPath("output/edited.txt");
$saveOptions->setHtmlPath($loadResult->getHtmlPath());
$saveOptions->setResourcesPath($loadResult->getResourcesPath());
$saveResult = $editApi->save(new Requests\saveRequest($saveOptions));
// Done.
echo "Document edited: " . $saveResult->getPath();
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-php-samples
use GroupDocs\Editor\Model;
use GroupDocs\Editor\Model\Requests;
$AppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$AppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$configuration = new GroupDocs\Editor\Configuration();
$configuration->setAppSid($AppSid);
$configuration->setAppKey($AppKey);
$editApi = new GroupDocs\Editor\EditApi($configuration);
$fileApi = new GroupDocs\Editor\FileApi($configuration);
// The document already uploaded into the storage
// Load it into editable state
$fileInfo = new Model\FileInfo();
$fileInfo->setFilePath("WordProcessing/password-protected.docx");
$fileInfo->setPassword("password");
$loadOptions = new Model\WordProcessingLoadOptions();
$loadOptions->setFileInfo($fileInfo);
$loadOptions->setOutputPath("output");
$loadResult = $editApi->load(new Requests\loadRequest($loadOptions));
// Download html document
$htmlFile = $fileApi->downloadFile(new Requests\downloadFileRequest($loadResult->getHtmlPath()));
$html = file_get_contents($htmlFile->getRealPath());
// Edit something...
$html = str_replace("Sample test text", "Hello world", $html);
// Upload html back to storage
file_put_contents($htmlFile->getRealPath(), $html);
$uploadRequest = new Requests\uploadFileRequest($loadResult->getHtmlPath(), $htmlFile->getRealPath());
$fileApi->uploadFile($uploadRequest);
// Save html back to docx
$saveOptions = new Model\WordProcessingSaveOptions();
$saveOptions->setFileInfo($fileInfo);
$saveOptions->setOutputPath("output/edited.docx");
$saveOptions->setHtmlPath($loadResult->getHtmlPath());
$saveOptions->setResourcesPath($loadResult->getResourcesPath());
$saveResult = $editApi->save(new Requests\saveRequest($saveOptions));
// Done.
echo "Document edited: " . $saveResult->getPath();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment