|
1 | | -# aspose-html-cloud-nodejs |
2 | | -JavaScript library for communicating with the Aspose.HTML for Cloud API |
| 1 | +# asposehtmlcloud |
| 2 | + |
| 3 | +Asposehtmlcloud - JavaScript client for asposehtmlcloud |
| 4 | + |
| 5 | +- API version: 1.0.1 |
| 6 | +- Package version: 1.0.1 |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +# Aspose.HTML Cloud SDK for Node.js |
| 11 | +This repository contains Aspose.HTML Cloud SDK for Node.js source code. |
| 12 | +This SDK allows you to work with Aspose.HTML Cloud REST APIs in your Node.js applications quickly and easily. |
| 13 | + |
| 14 | +See [API Reference](https://apireference.aspose.cloud/html/) for full API specification. |
| 15 | + |
| 16 | +## How to use the SDK? |
| 17 | +The complete source code is available in this repository folder, you can either directly use |
| 18 | +it in your project via npm package manager. |
| 19 | + |
| 20 | +### Prerequisites |
| 21 | + |
| 22 | +To use Aspose HTML for Cloud Node.js SDK you need to register an account with [Aspose Cloud](https://www.aspose.cloud/) and lookup/create App Key and SID at [Cloud Dashboard](https://dashboard.aspose.cloud/#/apps). There is free quota available. For more details, see [Aspose Cloud Pricing](https://purchase.aspose.cloud/pricing). |
| 23 | + |
| 24 | +### Installation |
| 25 | + |
| 26 | +#### Install Aspose.HTML Cloud |
| 27 | +### For [Node.js](https://nodejs.org/) |
| 28 | + |
| 29 | +#### npm |
| 30 | + |
| 31 | +To publish the library as a [npm](https://www.npmjs.com/), |
| 32 | +please follow the procedure in ["Publishing npm packages"](https://docs.npmjs.com/getting-started/publishing-npm-packages). |
| 33 | + |
| 34 | +Then install it via: |
| 35 | + |
| 36 | +```shell |
| 37 | +npm install asposehtmlcloud --save |
| 38 | +``` |
| 39 | + |
| 40 | +##### Local development |
| 41 | + |
| 42 | +To use the library locally without publishing to a remote npm registry, first install the dependencies by changing |
| 43 | +into the directory containing `package.json` (and this README). Let's call this `JAVASCRIPT_CLIENT_DIR`. Then run: |
| 44 | + |
| 45 | +```shell |
| 46 | +npm install |
| 47 | +``` |
| 48 | + |
| 49 | +Next, [link](https://docs.npmjs.com/cli/link) it globally in npm with the following, also from `JAVASCRIPT_CLIENT_DIR`: |
| 50 | + |
| 51 | +```shell |
| 52 | +npm link |
| 53 | +``` |
| 54 | + |
| 55 | +Finally, switch to the directory you want to use your asposehtmlcloud from, and run: |
| 56 | + |
| 57 | +```shell |
| 58 | +npm link /path/to/<JAVASCRIPT_CLIENT_DIR> |
| 59 | +``` |
| 60 | + |
| 61 | +You should now be able to `require('asposehtmlcloud')` in javascript files from the directory you ran the last |
| 62 | +command above from. |
| 63 | + |
| 64 | +#### git |
| 65 | +# |
| 66 | +If the library is hosted at a git repository, e.g. |
| 67 | +https://github.com/GIT_USER_ID/GIT_REPO_ID |
| 68 | +then install it via: |
| 69 | + |
| 70 | +```shell |
| 71 | + npm install GIT_USER_ID/GIT_REPO_ID --save |
| 72 | +``` |
| 73 | + |
| 74 | +### For browser |
| 75 | + |
| 76 | +The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following |
| 77 | +the above steps with Node.js and installing browserify with `npm install -g browserify`, |
| 78 | +perform the following (assuming *main.js* is your entry file, that's to say your javascript file where you actually |
| 79 | +use this library): |
| 80 | + |
| 81 | +```shell |
| 82 | +browserify main.js > bundle.js |
| 83 | +``` |
| 84 | + |
| 85 | +Then include *bundle.js* in the HTML pages. |
| 86 | + |
| 87 | +### Webpack Configuration |
| 88 | + |
| 89 | +Using Webpack you may encounter the following error: "Module not found: Error: |
| 90 | +Cannot resolve module", most certainly you should disable AMD loader. Add/merge |
| 91 | +the following section to your webpack config: |
| 92 | + |
| 93 | +```javascript |
| 94 | +module: { |
| 95 | + rules: [ |
| 96 | + { |
| 97 | + parser: { |
| 98 | + amd: false |
| 99 | + } |
| 100 | + } |
| 101 | + ] |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +### Sample usage |
| 106 | + |
| 107 | +Before fill all fields in /setting/config.json |
| 108 | + |
| 109 | +Example: |
| 110 | +```json |
| 111 | +{ |
| 112 | + "basePath":"https://api.aspose.cloud/v1.1", |
| 113 | + "authPath":"https://api.aspose.cloud/oauth2/token", |
| 114 | + "apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", |
| 115 | + "appSID":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", |
| 116 | + "testResult":"/testresult/", |
| 117 | + "testData":"/testdata/", |
| 118 | + "remoteFolder":"HtmlTestDoc/", |
| 119 | + "defaultUserAgent":"Webkit", |
| 120 | + "debugFile":"debug.log", |
| 121 | + "debug":false |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +## Getting Started |
| 128 | + |
| 129 | +Please follow the [installation](#installation) instruction and execute the following JS code: |
| 130 | + |
| 131 | +NOTE: Use the helper from /test/helper.js for upload and save data. |
| 132 | + |
| 133 | +```javascript |
| 134 | +// Load configurations data |
| 135 | +var fs = require('fs'); |
| 136 | +var conf = JSON.parse(fs.readFileSync(__dirname + '/../setting/config.json', 'utf8')); |
| 137 | + |
| 138 | +//Create storage api for upload to server |
| 139 | +var StorageApi = require('asposestoragecloud'); |
| 140 | +var storageApi = new StorageApi({ |
| 141 | + 'baseURI':conf['basePath'], |
| 142 | + 'appSid': conf['appSID'], |
| 143 | + 'apiKey': conf['apiKey'] , |
| 144 | + 'debug': conf['debug']}); |
| 145 | + |
| 146 | + |
| 147 | +// Setup local folder for source and result |
| 148 | +var local_dst_folder = __dirname + "/../"+ conf['testResult']; |
| 149 | +var local_src_folder = __dirname + "/../"+ conf['testData']; |
| 150 | + |
| 151 | + |
| 152 | +var Asposehtmlcloud = require('../src/index'); |
| 153 | + |
| 154 | +// Create Conversion Api object |
| 155 | +var api = new Asposehtmlcloud.ConversionApi(); |
| 156 | + |
| 157 | + |
| 158 | +var filename = "test_data.html"; // {String} Document name. |
| 159 | + |
| 160 | +// Get upload folder from config (or write manually) |
| 161 | +var folder = conf['remoteFolder']; |
| 162 | +var versionId = null; |
| 163 | +var storage=null; |
| 164 | + |
| 165 | +var file = local_src_folder + "/" + filename; |
| 166 | + |
| 167 | +//Upload file to storage |
| 168 | +storageApi.PutCreate(folder + "/" + filename, versionId, storage, file, callback); |
| 169 | + |
| 170 | +//Setup output format |
| 171 | +var outFormat = "png"; // {String} Resulting image format. |
| 172 | + |
| 173 | + |
| 174 | +//Setup various option for result image |
| 175 | +var opts = { |
| 176 | + 'width': 800, // {Number} Resulting image width. |
| 177 | + 'height': 1000, // {Number} Resulting image height. |
| 178 | + 'leftMargin': 10, // {Number} Left resulting image margin. |
| 179 | + 'rightMargin': 10, // {Number} Right resulting image margin. |
| 180 | + 'topMargin': 20, // {Number} Top resulting image margin. |
| 181 | + 'bottomMargin': 20, // {Number} Bottom resulting image margin. |
| 182 | + 'xResolution': 300, // {Number} Horizontal resolution of resulting image. |
| 183 | + 'yResolution': 300, // {Number} Vertical resolution of resulting image. |
| 184 | + 'folder': folder, // {String} The source document folder. |
| 185 | + 'storage': storage // {String} The source document storage. |
| 186 | +}; |
| 187 | + |
| 188 | +var callback = function(error, data, response) { |
| 189 | + if (error) { |
| 190 | + console.error(error); |
| 191 | + } else { |
| 192 | + var dst = local_dst_folder + "/" + "ResultConvertToPng.png"; |
| 193 | + var fd = fs.openSync(dst, 'w'); |
| 194 | + var len = fs.writeSync(fd, data); |
| 195 | + } |
| 196 | +}; |
| 197 | +api.GetConvertDocumentToImage(filename, outFormat, opts, callback); |
| 198 | + |
| 199 | +``` |
| 200 | + |
| 201 | +## Documentation for API Endpoints |
| 202 | + |
| 203 | +All URIs are relative to *https://api.aspose.cloud/v1.1* |
| 204 | + |
| 205 | +[Tests](./test/) contain various examples of using the Aspose.HTML SDK. |
| 206 | + |
| 207 | + |
| 208 | +Class | Method | HTTP request | Description |
| 209 | +------------ | ------------- | ------------- | ------------- |
| 210 | +*Asposehtmlcloud.ConversionApi* | [**GetConvertDocumentToImage**](docs/ConversionApi.md#GetConvertDocumentToImage) | **GET** /html/{name}/convert/image/{outFormat} | Convert the HTML document from the storage by its name to the specified image format. |
| 211 | +*Asposehtmlcloud.ConversionApi* | [**GetConvertDocumentToImageByUrl**](docs/ConversionApi.md#GetConvertDocumentToImageByUrl) | **GET** /html/convert/image/{outFormat} | Convert the HTML page from the web by its URL to the specified image format. |
| 212 | +*Asposehtmlcloud.ConversionApi* | [**GetConvertDocumentToPdf**](docs/ConversionApi.md#GetConvertDocumentToPdf) | **GET** /html/{name}/convert/pdf | Convert the HTML document from the storage by its name to PDF. |
| 213 | +*Asposehtmlcloud.ConversionApi* | [**GetConvertDocumentToPdfByUrl**](docs/ConversionApi.md#GetConvertDocumentToPdfByUrl) | **GET** /html/convert/pdf | Convert the HTML page from the web by its URL to PDF. |
| 214 | +*Asposehtmlcloud.ConversionApi* | [**GetConvertDocumentToXps**](docs/ConversionApi.md#GetConvertDocumentToXps) | **GET** /html/{name}/convert/xps | Convert the HTML document from the storage by its name to XPS. |
| 215 | +*Asposehtmlcloud.ConversionApi* | [**GetConvertDocumentToXpsByUrl**](docs/ConversionApi.md#GetConvertDocumentToXpsByUrl) | **GET** /html/convert/xps | Convert the HTML page from the web by its URL to XPS. |
| 216 | +*Asposehtmlcloud.DocumentApi* | [**GetDocument**](docs/DocumentApi.md#GetDocument) | **GET** /html/{name} | Return the HTML document by the name from default or specified storage. |
| 217 | +*Asposehtmlcloud.DocumentApi* | [**GetDocumentFragmentByXPath**](docs/DocumentApi.md#GetDocumentFragmentByXPath) | **GET** /html/{name}/fragments/{outFormat} | Return list of HTML fragments matching the specified XPath query. |
| 218 | +*Asposehtmlcloud.DocumentApi* | [**GetDocumentImages**](docs/DocumentApi.md#GetDocumentImages) | **GET** /html/{name}/images/all | Return all HTML document images packaged as a ZIP archive. |
| 219 | +*Asposehtmlcloud.OcrApi* | [**GetRecognizeAndImportToHtml**](docs/OcrApi.md#GetRecognizeAndImportToHtml) | **GET** /html/{name}/ocr/import | Recognize text from the image file in the storage and import it to HTML format. |
| 220 | +*Asposehtmlcloud.OcrApi* | [**GetRecognizeAndTranslateToHtml**](docs/OcrApi.md#GetRecognizeAndTranslateToHtml) | **GET** /html/{name}/ocr/translate/{srcLang}/{resLang} | Recognize text from the image file in the storage, import it to HTML format and translate to specified language. |
| 221 | +*Asposehtmlcloud.TranslationApi* | [**GetTranslateDocument**](docs/TranslationApi.md#GetTranslateDocument) | **GET** /html/{name}/translate/{srcLang}/{resLang} | Translate the HTML document specified by the name from default or specified storage. |
| 222 | +*Asposehtmlcloud.TranslationApi* | [**GetTranslateDocumentByUrl**](docs/TranslationApi.md#GetTranslateDocumentByUrl) | **GET** /html/translate/{srcLang}/{resLang} | Translate the HTML document from Web specified by its URL. |
| 223 | + |
| 224 | +## Run tests |
| 225 | +```shell |
| 226 | +node.exe ./node_modules/mocha/bin/_mocha --ui bdd ./test |
| 227 | +``` |
| 228 | + |
| 229 | + |
| 230 | +## Documentation for Authorization |
| 231 | + |
| 232 | +Please follow the [installation](#installation) instruction for write config file: |
| 233 | + |
| 234 | +[Authorization](https://docs.aspose.cloud/display/totalcloud/Authenticating+API+Requests) |
0 commit comments