|
1 | 1 | # GroupDocs.Conversion Cloud SDK for Java |
2 | 2 |
|
3 | | -This repository contains GroupDocs.Conversion Cloud SDK for Java source code. This SDK allows you to work with GroupDocs.Conversion Cloud REST APIs in your Java applications. |
| 3 | +This repository contains GroupDocs.Conversion Cloud SDK for Java 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 | ## Requirements |
6 | 6 |
|
@@ -47,61 +47,86 @@ dependencies { |
47 | 47 | } |
48 | 48 | ``` |
49 | 49 |
|
50 | | -## Getting Started |
| 50 | +### Create an account |
| 51 | +Creating an account is very simple. Go to Dashboard to create a free account. |
| 52 | +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). |
51 | 53 |
|
52 | | -* Please follow the [installation](#installation) instruction |
53 | | -* Get your AppSID and AppKey at [Dashboard](https://dashboard.groupdocs.cloud) and use them in your code |
54 | | -* Build and execute |
55 | | -* Explore more samples at [GitHub](https://github.com/groupdocs-conversion-cloud/groupdocs-conversion-cloud-java-samples) |
| 54 | +### Create an API client app |
| 55 | +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). |
56 | 56 |
|
57 | | -Example: |
| 57 | +## Convert document |
58 | 58 |
|
59 | 59 | ```java |
60 | 60 | import com.groupdocs.cloud.conversion.client.*; |
61 | | -import com.groupdocs.cloud.conversion.model.*; |
62 | | -import com.groupdocs.cloud.conversion.api.InfoApi; |
63 | | - |
| 61 | +import com.groupdocs.cloud.conversion.model.requests.*; |
| 62 | +import com.groupdocs.cloud.conversion.api.*; |
| 63 | +import java.io.File; |
64 | 64 | import java.util.*; |
65 | 65 |
|
66 | 66 | public class ApiExample { |
67 | 67 |
|
68 | 68 | public static void main(String[] args) { |
69 | | - //TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free registration is required). |
70 | | - String appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; |
71 | | - String appKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
72 | | - |
73 | | - Configuration configuration = new Configuration(appSid, appKey); |
74 | | - |
75 | | - InfoApi infoApi = new InfoApi(configuration); |
76 | | - |
77 | | - try { |
78 | | - FormatsResult response = infoApi.getSupportedFileFormats(); |
79 | | - for (Format format : response.getFormats()) { |
80 | | - System.out.println(format.getFileFormat()); |
81 | | - } |
82 | | - } catch (ApiException e) { |
83 | | - System.err.println("Failed to get supported file formats"); |
84 | | - e.printStackTrace(); |
85 | | - } |
| 69 | + //TODO: Get your ClientId and ClientSecret at https://dashboard.groupdocs.cloud (free registration is required). |
| 70 | + String ClientId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; |
| 71 | + String ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
| 72 | + |
| 73 | + Configuration configuration = new Configuration(ClientId, ClientSecret); |
| 74 | + |
| 75 | + ConvertApi apiInstance = new ConvertApi(configuration); |
| 76 | + |
| 77 | + File file = new File("myFile.docx"); |
| 78 | + |
| 79 | + ConvertDocumentDirectRequest request = new ConvertDocumentDirectRequest("pdf", file, 1, 0, null, null); |
| 80 | + |
| 81 | + File result = apiInstance.convertDocumentDirect(request); |
| 82 | + |
| 83 | + System.out.println("Document converted: " + result.length()); |
86 | 84 | } |
87 | 85 | } |
88 | 86 | ``` |
89 | 87 |
|
90 | | -## Manual build and installation from sources |
| 88 | +## Convert document using cloud storage |
| 89 | + |
| 90 | +```java |
| 91 | +import com.groupdocs.cloud.conversion.client.*; |
| 92 | +import com.groupdocs.cloud.conversion.model.requests.*; |
| 93 | +import com.groupdocs.cloud.conversion.api.*; |
| 94 | +import java.io.File; |
| 95 | +import java.util.*; |
| 96 | + |
| 97 | +public class ApiExample { |
91 | 98 |
|
92 | | -Building the API client library requires [Maven](https://maven.apache.org/) to be installed. |
93 | | -Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information. |
| 99 | + public static void main(String[] args) { |
| 100 | + //TODO: Get your ClientId and ClientSecret at https://dashboard.groupdocs.cloud (free registration is required). |
| 101 | + String ClientId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; |
| 102 | + String ClientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
94 | 103 |
|
95 | | -At first generate the JAR by executing following command in "/src" working directory: |
| 104 | + Configuration configuration = new Configuration(ClientId, ClientSecret); |
96 | 105 |
|
97 | | -```shell |
98 | | -mvn package -D maven.test.skip=true |
99 | | -``` |
| 106 | + FileApi fileApiInstance = new FileApi(configuration); |
| 107 | + ConvertApi apiInstance = new ConvertApi(configuration); |
100 | 108 |
|
101 | | -Then manually install the following JARs: |
| 109 | + // Upload file to cloud storage |
| 110 | + File file = new File("myFile.docx"); |
| 111 | + UploadFileRequest request = new UploadFileRequest("myFile.docx", file, null); |
| 112 | + fileApiInstance.uploadFileWithHttpInfo(request); |
102 | 113 |
|
103 | | -* target/groupdocs-conversion-cloud-25.6.jar |
104 | | -* target/lib/*.jar |
| 114 | + // Convert document |
| 115 | + ConvertSettings settings = new ConvertSettings(); |
| 116 | + settings.setFilePath("myFile.docx"); |
| 117 | + settings.setFormat("pdf"); |
| 118 | + settings.setOutputPath("converted"); |
| 119 | + |
| 120 | + List<StoredConvertedResult> result = apiInstance.convertDocument(new ConvertDocumentRequest(settings)); |
| 121 | + System.out.println("Document converted: " + result.get(0).getUrl()); |
| 122 | + |
| 123 | + // Download the result |
| 124 | + DownloadFileRequest request = new DownloadFileRequest("converted/myFile.pdf", null, null); |
| 125 | + File response = fileApiInstance.downloadFile(request); |
| 126 | + System.err.println("Expected response type is File: " + response.length()); |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
105 | 130 |
|
106 | 131 | ## Licensing |
107 | 132 |
|
|
0 commit comments