@@ -25,219 +25,153 @@ GroupDocs.Viewer Cloud SDK is written in different languages, all you need to ge
2525
2626## Make an API request
2727
28- Use the ** Client Id** and ** Client Secret** from the API app client you created in step one and replace in the corresponding code. Below is an example demonstrating using Formats API to get all supported file formats in GroupDocs.Viewer Cloud.
28+ Use the ** Client Id** and ** Client Secret** from the API app client you created in step one and replace in the corresponding code. Below is an example demonstrating how to preview document using GroupDocs.Viewer Cloud.
2929
3030{{< alert style="info" >}}The GitHub repository for [ GroupDocs.Viewer Cloud] ( https://github.com/groupdocs-viewer-cloud ) has a complete set of examples, demonstrating our API capabilities.{{< /alert >}}
3131
32- {{< tabs "example1">}}
32+ {{< tabs "example1-sdk ">}}
3333{{< tab "C#" >}}
34+ ``` cs
35+ // For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-dotnet-samples
36+ string MyClientSecret = " " ; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
37+ string MyClientId = " " ; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
3438
35- ``` csharp
36- // TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
37- var configuration = new Configuration
38- {
39- AppSid = " XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
40- AppKey = " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
41- };
42-
43- var apiInstance = new ViewerApi (configuration );
44-
45- try
46- {
47- var request = new GetSupportedFileFormatsRequest ();
48-
49- // Get supported file formats
50- var response = apiInstance .GetSupportedFileFormats (request );
51-
52- foreach (var format in response .Formats )
53- {
54- Debug .Print (format .ToString ());
55- }
56- }
57- catch (Exception e )
58- {
59- Debug .Print (" Exception when calling ViewerApi.DeleteFontsCache: " + e .Message );
60- }
61- ```
62-
63- {{< /tab >}}
64- {{< tab "Java" >}}
65-
66- ``` java
67-
68- // TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
69- String appSid = " xxxx" ;
70- String appKey = " xxx-xx" ;
71-
72- ViewerApi apiInstance = new ViewerApi (appSid, appKey);
73- try {
74- FormatCollection response = apiInstance. getSupportedFileFormats();
39+ var configuration = new Configuration (MyClientId , MyClientSecret );
40+ var apiInstance = new ViewApi (configuration );
7541
76- if (response. getFormats(). size() > 0 ) {
77- for (Format format : response. getFormats()) {
78- System . out. println(" Format: " + format. toString());
79- }
80- }
81- System . out. println(" Executed Successfully" );
82- } catch (ApiException e) {
83- System . err. println(" Exception when calling ViewerApi" );
84- e. printStackTrace();
85- }
42+ var format = " jpg" ;
43+ var request = new ConvertAndDownloadRequest (format , File .OpenRead (" myfile.txt" ));
44+ var result = apiInstance .ConvertAndDownload (request );
8645```
46+ {{< /tab >}}
47+ {{< tab "PHP">}}
48+ ``` php
49+ // For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-php-samples
50+ use GroupDocs\Viewer\Model;
51+ use GroupDocs\Viewer\Model\Requests;
8752
88- {{< /tab >}}
89- {{< tab "PHP" >}}
53+ $ClientId = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
54+ $ClientSecret = ""; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
9055
91- ``` php
92- //TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required).
9356$configuration = new GroupDocs\Viewer\Configuration();
94- $configuration->setAppSid($sid );
95- $configuration->setAppKey($key );
57+ $configuration->setAppSid($ClientId );
58+ $configuration->setAppKey($ClientSecret );
9659
97- $viewerApi = new GroupDocs\Viewer\ViewerApi ($configuration);
60+ $apiInstance = new GroupDocs\Viewer\ViewApi ($configuration);
9861
99- try {
100- $request = new GroupDocs\Viewer\Model\Requests\GetSupportedFileFormatsRequest();
101- $response = $viewerApi->getSupportedFileFormats($request);
62+ $format ="jpg";
63+ $path = __DIR__ . 'myfile.txt';
10264
103- foreach ($response->getFormats() as $key => $format) {
104- echo $format->getFileFormat() . " - " . $format->getExtension(), "\n";
105- }
106- } catch (Exception $e) {
107- echo "Something went wrong: ", $e->getMessage(), "\n";
108- }
65+ $request = new Requests\convertAndDownloadRequest($format, $path);
10966
67+ $result = $apiInstance->convertAndDownload($request);
11068```
69+ {{< /tab >}}
70+ {{< tab "Java">}}
71+ ``` java
11172
112- {{< /tab >}}
113- {{< tab "Node.js" >}}
73+ // For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-java-samples
74+ string MyClientSecret = " " ; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
75+ string MyClientId = " " ; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
11476
115- ``` js
116- " use strict" ;
117- exports .__esModule = true ;
118- // load the module
119- var groupdocs_viewer_cloud_1 = require (" groupdocs-viewer-cloud" );
120- // get your appSid and appKey at https://dashboard.groupdocs.cloud (free registration is required).
121- var appSid = " XXXX-XXXX-XXXXX" ;
122- var appKey = " XXXXXXXXXX" ;
123- // construct ViewerApi
124- var viewerApi = groupdocs_viewer_cloud_1 .ViewerApi .fromKeys (appSid, appKey);
125- // retrieve supported file-formats
126- viewerApi .getSupportedFileFormats ()
127- .then (function (result ) {
128- console .log (" Supported file-formats:" );
129- result .formats .forEach (function (format ) {
130- console .log (format .fileFormat + " (" + format .extension + " )" );
131- });
132- })[" catch" ](function (error ) {
133- console .log (" Error: " + error .message );
134- });
77+ Configuration configuration = new Configuration (MyClientId , MyClientSecret );
78+ ViewApi apiInstance = new ViewApi (configuration);
13579
136- ```
80+ String format = " pdf" ;
81+ File fileObj = new File (" myfile.txt" );
13782
138- {{< /tab >}}
139- {{< tab "Python" >}}
83+ ConvertAndDownloadRequest request = new ConvertAndDownloadRequest (format, fileObj, null , null );
14084
141- ``` python
142- # Import module
143- import groupdocs_viewer_cloud
144-
145- # Get your app_sid and app_key at https://dashboard.groupdocs.cloud (free registration is required).
146- app_sid = " XXX-XXXXXXX-XXXX "
147- app_key = " XXXXXXXXXXXXX "
85+ File file = apiInstance . convertAndDownload(request);
86+ ```
87+ {{< /tab >}}
88+ {{< tab "Ruby">}}
89+ ``` ruby
90+ # For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-ruby-samples
91+ require ' groupdocs_viewer_cloud '
14892
149- # Create instance of the GroupDocs Viewer APIapi = groupdocs_viewer_cloud.ViewerApi.from_keys(app_sid, app_key)
93+ $client_id = " XXXX-XXXX-XXXX-XXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
94+ $client_secret = " XXXXXXXXXXXXXXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
15095
151- try :
96+ apiInstance = GroupDocsViewerCloud :: ViewApi .from_keys( $client_id , $client_secret )
15297
153- response = api.get_supported_file_formats()
154- print ( ' Response: ' )
98+ format = " jpg "
99+ file = File . open ( " myfile.txt " , " r " )
155100
156- for format in response.formats:
157- print (' {0} ({1} )' .format(format .file_format, format .extension))
101+ request = ConvertAndDownloadRequest .new format , file
158102
159- except groupdocs_viewer_cloud.ApiException as e:
160- print (' Exception while calling Viewer API: {0} ' .format(e.message))
103+ response = apiInstance.convert_and_download(request)
161104```
105+ {{< /tab >}}
106+ {{< tab "Node.js">}}
107+ ``` js
108+ // For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-node-samples
109+ global .viewer # require (" groupdocs-viewer-cloud" );
162110
163- {{< /tab >}}
164- {{< tab "Ruby" >}}
165-
166- ``` ruby
167- # Load the gem
168- require ' groupdocs_viewer_cloud'
169- require ' ..\lib\groupdocs_viewer_cloud\api\viewer_api'
170-
171- # Get your app_sid and app_key at https://dashboard.groupdocs.cloud (free registration is required).
172- app_sid = " XXX-XXXXXXX-XXXX"
173- app_key = " XXXXXXXXXXXXX"
111+ global .clientId = " XXXX-XXXX-XXXX-XXXX" ; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
112+ global .clientSecret = " XXXXXXXXXXXXXXXX" ; // Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
174113
175- # Create instance of the API class
176- api = GroupDocsViewerCloud .from_keys(app_sid, app_key)
114+ global .viewApi = viewer_cloud .ViewApi .fromKeys (clientId, clientSecret);
177115
178- # Retrieve supported file-formats
179- response = api.get_supported_file_formats
116+ var format = " jpg " ;
117+ let filebuf = fs . readFileSync ( " myfile.txt " );
180118
181- # Print out supported file-formats
182- puts (" Supported file-formats:" )
183- response.formats.each do |format |
184- puts (" #{ format .file_format} (#{ format .extension} )" )
185- end
119+ var request = new ConvertAndDownloadRequest (format, filebuf);
120+ let response = await viewApi .convertAndDownload (request);
186121```
122+ {{< /tab >}}
123+ {{< tab "Python">}}
124+ ``` py
125+ # For complete examples and data files, please go to https://github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-python-samples
126+ import groupdocs_viewer_cloud
187127
188- {{< /tab >}}
189- {{< tab "Android" >}}
190-
191- ``` java
192- package examples.Supported_File_Formats ;
193-
194- import com.groupdocs.cloud.viewer.client.* ;
195- import com.groupdocs.cloud.viewer.model.* ;
196- import com.groupdocs.cloud.viewer.api.InfoApi ;
197- import examples.Utils ;
128+ client_id = " XXXX-XXXX-XXXX-XXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
129+ client_secret = " XXXXXXXXXXXXXXXX" # Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
198130
199- public class Viewer_Android_Get_Supported_Formats {
131+ apiInstance = groupdocs_viewer_cloud.ViewApi.from_keys(client_id, client_secret)
200132
201- public static void main (String [] args ) {
133+ format = " jpg"
134+ file = File.open(" myfile.txt" , " r" )
202135
203- InfoApi apiInstance = new InfoApi (Utils . AppSID , Utils . AppKey );
204- try {
205- FormatsResult response = apiInstance. getSupportedFileFormats();
136+ request = ConvertAndDownloadRequest.new format , file
206137
207- for (Format format : response. getFormats()) {
208- System . out. println(format. getFileFormat());
209- }
210- } catch (ApiException e) {
211- System . err. println(" Exception while calling InfoApi:" );
212- e. printStackTrace();
213- }
214- }
215- }
138+ response = apiInstance.convert_and_download(request)
216139```
217-
218140{{< /tab >}}
219141{{< tab "Go">}}
220142``` go
221143package basicUsage
222144
223145import (
224146 " fmt"
147+ " os"
225148
226149 " github.com/groupdocs-viewer-cloud/groupdocs-viewer-cloud-go-samples/config"
227150)
228151
229- func GetSupportedFormats () {
230-
231- response , _ , err := config.Client .InfoApi .GetSupportedFileFormats (config.Ctx )
152+ func ConvertAndDownload () {
153+ // Open the file to be converted
154+ file , err := os.Open (" Resources/SampleFiles/sample.docx" )
155+ if err != nil {
156+ fmt.Printf (" Exception: %v \n " , err)
157+ return
158+ }
159+ defer file.Close ()
232160
161+ // Call the API
162+ response , _ , err := config.Client .ViewApi .ConvertAndDownload (config.Ctx , " jpg" , file, nil )
233163 if err != nil {
234- fmt.Printf (" GetSupportedViewers error : %v \n " , err)
164+ fmt.Printf (" Exception : %v \n " , err)
235165 return
236166 }
237167
238- fmt.Printf (" Formats num: %v \n " , len (response.Formats ))
168+ fileInfo , err := response.Stat ()
169+ if err != nil {
170+ fmt.Printf (" Exception: %v \n " , err)
171+ return
172+ }
173+ fmt.Printf (" ConvertAndDownload completed: %v bytes received\n " , fileInfo.Size ())
239174}
240-
241175```
242176{{< /tab >}}
243177{{< /tabs >}}
0 commit comments