Skip to content

Commit 5bde385

Browse files
Update README.md
1 parent 43fdbdf commit 5bde385

1 file changed

Lines changed: 60 additions & 24 deletions

File tree

README.md

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
# GroupDocs.Conversion Cloud SDK for PHP
22

3-
This repository contains GroupDocs.Conversion Cloud SDK for PHP source code. This SDK allows you to work with GroupDocs.Conversion Cloud REST APIs in your PHP applications.
3+
This repository contains GroupDocs.Conversion Cloud SDK for PHP source code. This SDK has been developed to help you get started with using our document conversion REST API, allowing to seamlessly convert your documents to any format you need. With this single API, you can convert back and forth between over 50 types of documents and images, including all Microsoft Office and OpenDocument file formats, PDF documents, HTML, CAD, raster images and many more.
44

5-
## Dependencies
6-
7-
- PHP 5.5 or later
8-
9-
## Authorization
10-
11-
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).
12-
13-
## Installation & Usage
5+
## Installation
146

157
### Composer
168

@@ -46,37 +38,81 @@ Clone or download this repository, then run `composer install` in the root direc
4638
require_once('/path/to/groupdocs-conversion-cloud-php/vendor/autoload.php');
4739
```
4840

49-
## Tests
5041

51-
To run the unit tests set your AppSID and AppKey in [json.config](tests/GroupDocs/Conversion/config.json) and execute following commands:
42+
### Create an account
43+
Creating an account is very simple. Go to Dashboard to create a free account.
44+
We’re using Single Sign On across our websites, therefore, if you already have an account with our services, you can use it to also access the [Dashboard](https://dashboard.groupdocs.cloud).
5245

53-
```shell
54-
php composer.phar install ./vendor/bin/phpunit
55-
```
46+
### Create an API client app
47+
Before you can make any requests to GroupDocs Cloud API you need to get a Client Id and a Client Secret. This will be used to invoke GroupDocs Cloud API. You can get it by creating a new [Application](https://dashboard.groupdocs.cloud/applications).
48+
49+
## Convert document
50+
51+
```php
52+
<?php
53+
54+
require_once(__DIR__ . '/vendor/autoload.php');
55+
56+
//TODO: Get your Client Id and a Client Secret at https://dashboard.groupdocs.cloud (free registration is required).
57+
$configuration = new GroupDocs\Conversion\Configuration();
58+
$configuration->setAppSid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
59+
$configuration->setAppKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
60+
61+
$apiInstance = new GroupDocs\Conversion\ConvertApi($configuration);
62+
63+
try {
64+
// Prepare request
65+
$filePath = dirname(realpath(__DIR__)) . '/myFile.docx';
66+
$request = new Requests\ConvertDocumentDirectRequest("pdf", $filePath);
67+
68+
// Convert
69+
$result = $apiInstance->convertDocumentDirect($request);
70+
71+
// Done
72+
echo "Document converted: " . $result->getSize();
73+
echo "\n";
74+
} catch (Exception $e) {
75+
echo "Something went wrong: ", $e->getMessage(), "\n";
76+
PHP_EOL;
77+
}
5678

57-
## Getting Started
79+
?>
80+
```
5881

59-
Please follow the [installation procedure](#installation--usage) and then run the following:
82+
## Convert document using cloud storage
6083

6184
```php
6285
<?php
6386

6487
require_once(__DIR__ . '/vendor/autoload.php');
6588

66-
//TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
89+
//TODO: Get your Client Id and a Client Secret at https://dashboard.groupdocs.cloud (free registration is required).
6790
$configuration = new GroupDocs\Conversion\Configuration();
6891
$configuration->setAppSid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
6992
$configuration->setAppKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
7093

71-
$api = new GroupDocs\Conversion\InfoApi($configuration);
94+
$fileApi = new GroupDocs\Conversion\FileApi($configuration);
95+
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);
7296

7397
try {
74-
$request = new GroupDocs\Conversion\Model\Requests\GetSupportedConversionTypesRequest();
75-
$response = $api->getSupportedConversionTypes($request);
98+
// Upload file to cloud storage
99+
$putCreateRequest = new \GroupDocs\Conversion\Model\Requests\uploadFileRequest('myFile.docx', './myFile.docx');
100+
$putCreateResponse = $fileApi->uploadFile($putCreateRequest);
101+
102+
// Convert
103+
$settings = new \GroupDocs\Conversion\Model\ConvertSettings();
104+
$settings->setFilePath('myFile.docx');
105+
$settings->setFormat("pdf");
106+
$settings->setOutputPath("converted");
107+
$result = $convertApi->convertDocument(new \GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings));
108+
echo "Document converted: " . $result[0]->getUrl();
109+
echo "\n";
110+
111+
// Download converted document
112+
$request = new GroupDocs\Conversion\Model\Requests\DownloadFileRequest("converted/myFile.pdf", null, null);
113+
$response = $fileApi->downloadFile($request);
114+
echo "Expected response type is File: ", strlen($response);
76115

77-
foreach($response as $key => $format) {
78-
echo $format->getSourceFormat();
79-
}
80116
} catch (Exception $e) {
81117
echo "Something went wrong: ", $e->getMessage(), "\n";
82118
PHP_EOL;

0 commit comments

Comments
 (0)