Skip to content

Commit 541090f

Browse files
Update README.md
1 parent 498d6dc commit 541090f

1 file changed

Lines changed: 58 additions & 46 deletions

File tree

README.md

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GroupDocs.Conversion Cloud Node.js SDK
22

3-
Node.js module for communicating with the GroupDocs.Conversion Cloud API
3+
This repository contains GroupDocs.Conversion Cloud SDK for Node.js 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

55
## Installation
66

@@ -10,62 +10,74 @@ A package `groupdocs-conversion-cloud` is available at [npmjs.com](https://www.n
1010
npm install groupdocs-conversion-cloud
1111
```
1212

13-
## Getting Started
13+
### Create an account
14+
Creating an account is very simple. Go to Dashboard to create a free account.
15+
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).
1416

15-
Please follow the [installation](#installation) procedure and then run the following JavaScript code:
17+
### Create an API client app
18+
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).
19+
20+
## Convert document
1621

1722
```js
18-
// load the module
19-
var GroupDocs = require('groupdocs-conversion-cloud');
20-
21-
// get your appSid and appKey at https://dashboard.groupdocs.cloud (free registration is required).
22-
var appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
23-
var appKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
24-
25-
// construct Api
26-
var api = GroupDocs.InfoApi.fromKeys(appSid, appKey);
27-
var request = new GroupDocs.GetSupportedConversionTypesRequest();
28-
// retrieve supported conversion types
29-
api.getSupportedConversionTypes(request)
30-
.then(function (response) {
31-
console.log("Supported file-formats:")
32-
response.forEach(function (format) {
33-
console.log(format.sourceFormat + ": [" + format.targetFormats.join(", ") + "]");
34-
});
35-
})
36-
.catch(function (error) {
37-
console.log("Error: " + error.message)
38-
});
39-
```
23+
"use strict";
24+
global.conversion_cloud = require("groupdocs-conversion-cloud");
25+
global.fs = require("fs");
4026

41-
Or compile and run same written in TypeScript:
27+
global.clientId = "XXXX-XXXX-XXXX-XXXX";
28+
global.clientSecret = "XXXXXXXXXXXXXXXX";
4229

43-
```ts
44-
// load the module
45-
import { INfoApi, GetSupportedConversionTypesRequest } from "groupdocs-conversion-cloud";
30+
const config = new conversion_cloud.Configuration(clientId, clientSecret);
31+
config.apiBaseUrl = "https://api.groupdocs.cloud";
4632

47-
// get your appSid and appKey at https://dashboard.groupdocs.cloud (free registration is required).
48-
const appSid: string = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
49-
const appKey: string = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
33+
global.convertApi = conversion_cloud.ConvertApi.fromConfig(config);
5034

51-
// construct Api
52-
const api: InfoApi = InfoApi.fromKeys(appSid, appKey);
35+
(async () => {
36+
let file = fs.readFileSync('./myFile.docx');
37+
let request = new conversion_cloud.ConvertDocumentDirectRequest("pdf", file);
38+
let result = await convertApi.convertDocumentDirect(request);
39+
console.log("Document converted: " + result.length);
40+
})();
41+
```
5342

54-
const request: GetSupportedConversionTypesRequest = new GetSupportedConversionTypesRequest();
43+
## Convert document using cloud storage
5544

56-
// retrieve supported file-formats
57-
api.getSupportedConversionTypes(request)
58-
.then((result) => {
59-
console.log("Supported file-formats:");
60-
result.forEach((format) => {
61-
console.log(format.sourceFormat + ": [" + format.targetFormats.join(", ") + "]");
62-
});
63-
})
64-
.catch((error) => {
65-
console.log("Error: " + error.message);
66-
});
45+
```js
46+
"use strict";
47+
global.conversion_cloud = require("groupdocs-conversion-cloud");
48+
global.fs = require("fs");
49+
50+
global.clientId = "XXXX-XXXX-XXXX-XXXX";
51+
global.clientSecret = "XXXXXXXXXXXXXXXX";
52+
53+
const config = new conversion_cloud.Configuration(clientId, clientSecret);
54+
config.apiBaseUrl = "https://api.groupdocs.cloud";
55+
56+
global.convertApi = conversion_cloud.ConvertApi.fromConfig(config);
57+
global.fileApi = conversion_cloud.FileApi.fromConfig(config);
58+
59+
(async () => {
60+
// Upload file to cloud storage
61+
let file = fs.readFileSync('./myFile.docx');
62+
var uploadRequest = new conversion_cloud.UploadFileRequest("myFile.docx", file);
63+
await fileApi.uploadFile(uploadRequest);
64+
65+
// Convert
66+
let settings = new conversion_cloud.ConvertSettings();
67+
settings.filePath = "myFile.docx";
68+
settings.format = "pdf";
69+
settings.outputPath = "converted";
70+
71+
let result = await convertApi.convertDocument(new conversion_cloud.ConvertDocumentRequest(settings));
72+
console.log("Document converted: " + result[0].url);
73+
74+
// Download result
75+
var response = await fileApi.downloadFile(new conversion_cloud.DownloadFileRequest("converted/myFile.pdf", null))
76+
console.log("Expected response type is Stream: " + response.length);
77+
})();
6778
```
6879

80+
6981
## Licensing
7082

7183
GroupDocs.Conversion Cloud Node.js SDK licensed under [MIT License](LICENSE).

0 commit comments

Comments
 (0)