|
1 | 1 | # GroupDocs.Conversion Cloud SDK for Android |
2 | 2 |
|
3 | | -This repository contains GroupDocs.Conversion Cloud SDK for Android source code. This SDK allows you to work with GroupDocs.Conversion Cloud REST APIs in your Android applications on Java language. |
| 3 | +This repository contains GroupDocs.Conversion Cloud SDK for Android 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 | 5 | ## Installation |
6 | 6 |
|
@@ -29,38 +29,83 @@ dependencies { |
29 | 29 | } |
30 | 30 | ``` |
31 | 31 |
|
32 | | -## Getting Started |
| 32 | +### Create an account |
| 33 | +Creating an account is very simple. Go to Dashboard to create a free account. |
| 34 | +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 acccess the [Dashboard](https://dashboard.groupdocs.cloud). |
33 | 35 |
|
34 | | -Please follow the [installation](#installation) instruction and use the following Java code: |
| 36 | +### Create an API client app |
| 37 | +Before you can make any requests to GroupDocs Cloud API you need to get a Client Id and a Client Secret. This will will be used to invoke GroupDocs Cloud API. You can get it by creating a new [Application](https://dashboard.groupdocs.cloud/applicationsV). |
| 38 | + |
| 39 | +## Convert document |
35 | 40 |
|
36 | 41 | ```java |
37 | 42 | import com.groupdocs.cloud.conversion.client.*; |
38 | | -import com.groupdocs.cloud.conversion.model.*; |
39 | | -import com.groupdocs.cloud.conversion.api.InfoApi; |
| 43 | +import com.groupdocs.cloud.conversion.model.requests.*; |
| 44 | +import com.groupdocs.cloud.conversion.api.*; |
| 45 | +import java.io.File; |
| 46 | +import java.util.*; |
| 47 | + |
| 48 | +public class ApiExample { |
| 49 | + |
| 50 | + public static void main(String[] args) { |
| 51 | + //TODO: Get your ClientId and ClientSecret at https://dashboard.groupdocs.cloud (free registration is required). |
| 52 | + String ClientId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; |
| 53 | + String ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
| 54 | + |
| 55 | + Configuration configuration = new Configuration(ClientId, ClientSecret); |
40 | 56 |
|
| 57 | + ConvertApi apiInstance = new ConvertApi(configuration); |
| 58 | + |
| 59 | + File file = new File("myFile.docx"); |
| 60 | + |
| 61 | + ConvertDocumentDirectRequest request = new ConvertDocumentDirectRequest("pdf", file, 1, 0, null, null); |
| 62 | + |
| 63 | + File result = apiInstance.convertDocumentDirect(request); |
| 64 | + |
| 65 | + System.out.println("Document converted: " + result.length()); |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +## Convert document using cloud storage |
| 71 | + |
| 72 | +```java |
| 73 | +import com.groupdocs.cloud.conversion.client.*; |
| 74 | +import com.groupdocs.cloud.conversion.model.requests.*; |
| 75 | +import com.groupdocs.cloud.conversion.api.*; |
| 76 | +import java.io.File; |
| 77 | +import java.util.*; |
41 | 78 |
|
42 | 79 | public class ApiExample { |
43 | 80 |
|
44 | | - public static void getSupportedFormats() { |
| 81 | + public static void main(String[] args) { |
| 82 | + //TODO: Get your ClientId and ClientSecret at https://dashboard.groupdocs.cloud (free registration is required). |
| 83 | + String ClientId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; |
| 84 | + String ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
| 85 | + |
| 86 | + Configuration configuration = new Configuration(ClientId, ClientSecret); |
45 | 87 |
|
46 | | - //TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required). |
47 | | - String appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; |
48 | | - String appKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
| 88 | + FileApi fileApiInstance = new FileApi(configuration); |
| 89 | + ConvertApi apiInstance = new ConvertApi(configuration); |
49 | 90 |
|
50 | | - Configuration configuration = new Configuration(appSid, appKey); |
| 91 | + // Upload file to cloud storage |
| 92 | + File file = new File("myFile.docx"); |
| 93 | + UploadFileRequest request = new UploadFileRequest("myFile.docx", file, null); |
| 94 | + fileApiInstance.uploadFileWithHttpInfo(request); |
51 | 95 |
|
52 | | - InfoApi infoApi = new InfoApi(configuration); |
| 96 | + // Convert document |
| 97 | + ConvertSettings settings = new ConvertSettings(); |
| 98 | + settings.setFilePath("myFile.docx"); |
| 99 | + settings.setFormat("pdf"); |
| 100 | + settings.setOutputPath("converted"); |
53 | 101 |
|
54 | | - try { |
55 | | - FormatsResult response = infoApi.getSupportedFileFormats(); |
56 | | - for (Format format : response.getFormats()) { |
57 | | - System.out.println(format.getFileFormat()); |
58 | | - } |
59 | | - } catch (ApiException e) { |
60 | | - System.err.println("Failed to get supported file formats"); |
61 | | - e.printStackTrace(); |
62 | | - } |
| 102 | + List<StoredConvertedResult> result = apiInstance.convertDocument(new ConvertDocumentRequest(settings)); |
| 103 | + System.out.println("Document converted: " + result.get(0).getUrl()); |
63 | 104 |
|
| 105 | + // Download the result |
| 106 | + DownloadFileRequest request = new DownloadFileRequest("converted/myFile.pdf", null, null); |
| 107 | + File response = fileApiInstance.downloadFile(request); |
| 108 | + System.err.println("Expected response type is File: " + response.length()); |
64 | 109 | } |
65 | 110 | } |
66 | 111 | ``` |
|
0 commit comments