JavaScript library for communicating with the Aspose.HTML for Cloud API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
setting
src
test
testdata
.gitignore
LICENSE
README.md
mocha.opts
package-lock.json
package.json

README.md

asposehtmlcloud

Asposehtmlcloud - JavaScript client for asposehtmlcloud

  • API version: 1.0.1
  • Package version: 1.0.1

Installation

Aspose.HTML Cloud SDK for Node.js

This repository contains Aspose.HTML Cloud SDK for Node.js source code. This SDK allows you to work with Aspose.HTML Cloud REST APIs in your Node.js applications quickly and easily.

See API Reference for full API specification.

How to use the SDK?

The complete source code is available in this repository folder, you can either directly use it in your project via npm package manager.

Prerequisites

To use Aspose HTML for Cloud Node.js SDK you need to register an account with Aspose Cloud and lookup/create App Key and SID at Cloud Dashboard. There is free quota available. For more details, see Aspose Cloud Pricing.

Installation

Install Aspose.HTML Cloud

For Node.js

npm

To publish the library as a npm, please follow the procedure in "Publishing npm packages".

Then install it via:

npm install asposehtmlcloud --save
Local development

To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing package.json (and this README). Let's call this JAVASCRIPT_CLIENT_DIR. Then run:

npm install

Next, link it globally in npm with the following, also from JAVASCRIPT_CLIENT_DIR:

npm link

Finally, switch to the directory you want to use your asposehtmlcloud from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('asposehtmlcloud') in javascript files from the directory you ran the last command above from.

git

If the library is hosted at a git repository, e.g. https://github.com/GIT_USER_ID/GIT_REPO_ID then install it via:

    npm install GIT_USER_ID/GIT_REPO_ID --save

For browser

The library also works in the browser environment via npm and browserify. After following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following (assuming main.js is your entry file, that's to say your javascript file where you actually use this library):

browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Sample usage

Before fill all fields in /setting/config.json

Example:

{
    "basePath":"https://api.aspose.cloud/v1.1",
    "authPath":"https://api.aspose.cloud/oauth2/token",
    "apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "appSID":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "testResult":"/testresult/",
    "testData":"/testdata/",
    "remoteFolder":"HtmlTestDoc/",
    "defaultUserAgent":"Webkit"
}

Getting Started

Please follow the installation instruction and execute the following JS code:

NOTE: Use the helper from /test/helper.js for upload and save data.

// Load configurations data
var fs = require('fs');
var conf = JSON.parse(fs.readFileSync(__dirname + '/../setting/config.json', 'utf8'));

//Create storage api for upload to server
var StorageApi = require('asposestoragecloud');
var storageApi = new StorageApi({
  'baseURI':conf['basePath'],
  'appSid': conf['appSID'],
  'apiKey': conf['apiKey']});


// Setup local folder for source and result
var local_dst_folder = __dirname + "/../"+ conf['testResult'];
var local_src_folder = __dirname + "/../"+ conf['testData'];


var Asposehtmlcloud = require('../src/index');

// Create Conversion Api object
var api = new Asposehtmlcloud.ConversionApi();


var filename = "test_data.html"; // {String} Document name.

// Get upload folder from config (or write manually)
var folder = conf['remoteFolder'];
var versionId = null;
var storage=null;

var file = local_src_folder + "/" + filename;

//Upload file to storage
storageApi.PutCreate(folder + "/" + filename, versionId, storage, file, callback);

//Setup output format
var outFormat = "png"; // {String} Resulting image format.


//Setup various option for result image
var opts = {
  'width': 800, // {Number} Resulting image width.
  'height': 1000, // {Number} Resulting image height.
  'leftMargin': 10, // {Number} Left resulting image margin.
  'rightMargin': 10, // {Number} Right resulting image margin.
  'topMargin': 20, // {Number} Top resulting image margin.
  'bottomMargin': 20, // {Number} Bottom resulting image margin.
  'xResolution': 300, // {Number} Horizontal resolution of resulting image.
  'yResolution': 300, // {Number} Vertical resolution of resulting image.
  'folder': folder, // {String} The source document folder.
  'storage': storage // {String} The source document storage.
};

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    var dst = local_dst_folder + "/" + "ResultConvertToPng.png";
    var fd = fs.openSync(dst, 'w');
    var len = fs.writeSync(fd, data);
  }
};
api.GetConvertDocumentToImage(filename, outFormat, opts, callback);

Documentation for API Endpoints

All URIs are relative to https://api.aspose.cloud/v1.1

Tests contain various examples of using the Aspose.HTML SDK.

HTML SDK

Class Method HTTP request Description
Asposehtmlcloud.ConversionApi GetConvertDocumentToImage GET /html/{name}/convert/image/{outFormat} Convert the HTML document from the storage by its name to the specified image format.
Asposehtmlcloud.ConversionApi GetConvertDocumentToImageByUrl GET /html/convert/image/{outFormat} Convert the HTML page from the web by its URL to the specified image format.
Asposehtmlcloud.ConversionApi GetConvertDocumentToPdf GET /html/{name}/convert/pdf Convert the HTML document from the storage by its name to PDF.
Asposehtmlcloud.ConversionApi GetConvertDocumentToPdfByUrl GET /html/convert/pdf Convert the HTML page from the web by its URL to PDF.
Asposehtmlcloud.ConversionApi GetConvertDocumentToXps GET /html/{name}/convert/xps Convert the HTML document from the storage by its name to XPS.
Asposehtmlcloud.ConversionApi GetConvertDocumentToXpsByUrl GET /html/convert/xps Convert the HTML page from the web by its URL to XPS.
Asposehtmlcloud.ConversionApi PutConvertDocumentInRequestToImage PUT /html/convert/image/{outFormat} Converts the HTML document (in request content) to the specified image format and uploads resulting file to storage.
Asposehtmlcloud.ConversionApi PutConvertDocumentInRequestToPdf PUT /html/convert/pdf Converts the HTML document (in request content) to PDF and uploads resulting file to storage.
Asposehtmlcloud.ConversionApi PutConvertDocumentInRequestToXps PUT /html/convert/xps Converts the HTML document (in request content) to XPS and uploads resulting file to storage.
Asposehtmlcloud.ConversionApi PutConvertDocumentToImage PUT /html/{name}/convert/image/{outFormat} Converts the HTML document (located on storage) to the specified image format and uploads resulting file to storage.
Asposehtmlcloud.ConversionApi PutConvertDocumentToPdf PUT /html/{name}/convert/pdf Converts the HTML document (located on storage) to PDF and uploads resulting file to storage.
Asposehtmlcloud.ConversionApi PutConvertDocumentToXps PUT /html/{name}/convert/xps Converts the HTML document (located on storage) to XPS and uploads resulting file to storage.
Asposehtmlcloud.DocumentApi GetDocumentFragmentByXPath GET /html/{name}/fragments/{outFormat} Return list of HTML fragments matching the specified XPath query.
Asposehtmlcloud.DocumentApi GetDocumentFragmentByXPathByUrl GET /html/fragments/{outFormat} Return list of HTML fragments matching the specified XPath query by the source page URL.
Asposehtmlcloud.DocumentApi GetDocumentFragmentsByCSSSelector GET /html/{name}/fragments/css/{outFormat} Return list of HTML fragments matching the specified CSS selector.
Asposehtmlcloud.DocumentApi GetDocumentFragmentsByCSSSelectorByUrl GET /html/fragments/css/{outFormat} Return list of HTML fragments matching the specified CSS selector by the source page URL.
Asposehtmlcloud.DocumentApi GetDocumentImages GET /html/{name}/images/all Return all HTML document images packaged as a ZIP archive.
Asposehtmlcloud.DocumentApi GetDocumentImagesByUrl GET /html/images/all Return all HTML page images packaged as a ZIP archive by the source page URL.
Asposehtmlcloud.OcrApi GetRecognizeAndImportToHtml GET /html/{name}/ocr/import Recognize text from the image file in the storage and import it to HTML format.
Asposehtmlcloud.OcrApi 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.
Asposehtmlcloud.TranslationApi GetTranslateDocument GET /html/{name}/translate/{srcLang}/{resLang} Translate the HTML document specified by the name from default or specified storage.
Asposehtmlcloud.TranslationApi GetTranslateDocumentByUrl GET /html/translate/{srcLang}/{resLang} Translate the HTML document from Web specified by its URL.
Asposehtmlcloud.SummarizationApi GetDetectHtmlKeywords GET /html/{name}/summ/keywords Get the HTML document keywords using the keyword detection service.
Asposehtmlcloud.SummarizationApi GetDetectHtmlKeywordsByUrl GET /html/summ/keywords Get the keywords from HTML document from Web specified by its URL using the keyword detection service
Asposehtmlcloud.TemplateMergeApi GetMergeHtmlTemplate GET /html/{templateName}/merge Populate HTML document template with data located as a file in the storage.
Asposehtmlcloud.TemplateMergeApi PutMergeHtmlTemplate PUT /html/{templateName}/merge Populate HTML document template with data from the request body. Result document will be saved to storage.

STORAGE SDK

Class Method HTTP request Description
Asposehtmlcloud.StorageApi deleteFile DELETE /storage/file Remove a specific file
Asposehtmlcloud.StorageApi getDownload GET /storage/file Download a specific file
Asposehtmlcloud.StorageApi postMoveFile POST /storage/file Move a specific file
Asposehtmlcloud.StorageApi putCreate PUT /storage/file Upload a specific file
Asposehtmlcloud.StorageApi deleteFolder DELETE /storage/folder Remove a specific folder
Asposehtmlcloud.StorageApi getListFiles GET /storage/folder Get the file listing of a specific folder
Asposehtmlcloud.StorageApi postMoveFolder POST /storage/folder Move a specific folder
Asposehtmlcloud.StorageApi putCreateFolder PUT /storage/folder Create the folder
Asposehtmlcloud.StorageApi getDiscUsage GET /storage/disc Check the disk usage of the current account
Asposehtmlcloud.StorageApi getIsExist GET /storage/exist Check if a specific file or folder exists
Asposehtmlcloud.StorageApi getIsStorageExist GET /storage/{name}/exist Check if storage exists
Asposehtmlcloud.StorageApi getListFileVersions GET /storage/version Get the file's versions list

Documentation for Models

Run tests

node.exe ./node_modules/mocha/bin/_mocha --ui bdd ./test

Documentation for Authorization

Please follow the installation instruction for write config file:

Authorization