|
1 | 1 | # GroupDocs.Conversion Cloud SDK for PHP |
2 | 2 |
|
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. |
4 | 4 |
|
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 |
14 | 6 |
|
15 | 7 | ### Composer |
16 | 8 |
|
@@ -46,37 +38,81 @@ Clone or download this repository, then run `composer install` in the root direc |
46 | 38 | require_once('/path/to/groupdocs-conversion-cloud-php/vendor/autoload.php'); |
47 | 39 | ``` |
48 | 40 |
|
49 | | -## Tests |
50 | 41 |
|
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). |
52 | 45 |
|
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 | +} |
56 | 78 |
|
57 | | -## Getting Started |
| 79 | +?> |
| 80 | +``` |
58 | 81 |
|
59 | | -Please follow the [installation procedure](#installation--usage) and then run the following: |
| 82 | +## Convert document using cloud storage |
60 | 83 |
|
61 | 84 | ```php |
62 | 85 | <?php |
63 | 86 |
|
64 | 87 | require_once(__DIR__ . '/vendor/autoload.php'); |
65 | 88 |
|
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). |
67 | 90 | $configuration = new GroupDocs\Conversion\Configuration(); |
68 | 91 | $configuration->setAppSid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); |
69 | 92 | $configuration->setAppKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); |
70 | 93 |
|
71 | | -$api = new GroupDocs\Conversion\InfoApi($configuration); |
| 94 | +$fileApi = new GroupDocs\Conversion\FileApi($configuration); |
| 95 | +$convertApi = new GroupDocs\Conversion\ConvertApi($configuration); |
72 | 96 |
|
73 | 97 | 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); |
76 | 115 |
|
77 | | - foreach($response as $key => $format) { |
78 | | - echo $format->getSourceFormat(); |
79 | | - } |
80 | 116 | } catch (Exception $e) { |
81 | 117 | echo "Something went wrong: ", $e->getMessage(), "\n"; |
82 | 118 | PHP_EOL; |
|
0 commit comments