@asposecloud/aspose-html-cloud

22.12.1 • Public • Published

Aspose.Html Cloud Node.js SDK

Aspose.Html Cloud is a true REST API that enables you to perform a wide range of html processing operations including manipulation and conversion in the cloud, with zero initial costs. Our Cloud SDKs are wrappers around REST API in various programming languages, allowing you to process html pages in language of your choice quickly and easily, gaining all benefits of strong types and IDE highlights.

  • API version: 22.12.1
  • Package version: 22.12.1

Possible conversions:

  • HTML -> PDF, XPS, DOCX, MD, MHTML, JPEG, BMP, PNG, TIFF, GIF
  • EPUB -> PDF, XPS, DOCX, JPEG, BMP, PNG, TIFF, GIF
  • MD -> PDF, XPS, DOCX, HTML, MHTML, JPEG, BMP, PNG, TIFF, GIF
  • MHTML -> PDF, XPS, DOCX, JPEG, BMP, PNG, TIFF, GIF
  • SVG -> PDF, XPS, JPEG, BMP, PNG, TIFF, GIF
  • JPEG, BMP, PNG, TIFF, GIF -> SVG

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 a free quota available. For more details, see Aspose Cloud Pricing.

Install Aspose.HTML Cloud

For Node.js

npm

npm install @asposecloud/aspose-html-cloud --save

git

Install it via:

    npm install https://github.com/aspose-html-cloud/aspose-html-cloud-nodejs --save

Getting Started

  1. Sign Up. Before you begin, you need to sign up for an account on our Dashboard and retrieve your credentials.
  2. Minimum requirements. This SDK requires Node.js 6.x and higher.
  3. Install Aspose.Html Cloud Node.js SDK.

Please, add the following nmp package to your project.json as a dependency.

{
  "dependencies": {
    "@asposecloud/aspose-html-cloud":"^22.12.1"
  }
}

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

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

    // Get keys from aspose site.
    // There is free quota available. 
    // For more details, see https://purchase.aspose.cloud/pricing
	
var conf = {
    "basePath":"https://api.aspose.cloud/v4.0",
    "authPath":"https://api.aspose.cloud/connect/token",
    "apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "appSID":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "defaultUserAgent":"NodeJsWebkit"
};

var api = require('@asposecloud/aspose-html-cloud');

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


var src = "/path/to/src/test.html"; // {String} Source document.
var dst = "/path/to/dst/test.jpeg"; // {String} Result document.


//Setup various option for result image
var opts = {
  'width': 800, // {Number} Resulting image width in pixels.
  'height': 1000, // {Number} Resulting image height in pixels.
  'leftMargin': 10, // {Number} Left resulting image margin in pixels.
  'rightMargin': 10, // {Number} Right resulting image margin in pixels.
  'topMargin': 20, // {Number} Top resulting image margin in pixels.
  'bottomMargin': 20 // {Number} Bottom resulting image margin in pixels.

};

var callback = function(error, data, response) {
  if (error) {
    console.error(error);
  } else {
    console.log(data);  
  }
};

conversionApi.convertLocalToLocal(src, dst, opts, callback);
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 package from, and run:

npm link /path/to/<JAVASCRIPT_CLIENT_DIR>

You should now be able to require('@asposecloud/aspose-html-cloud') in javascript files from the directory you ran the last command above from.

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 configuration object (see tests)

Example:

var conf = {
    "basePath":"https://api.aspose.cloud/v4.0",
    "authPath":"https://api.aspose.cloud/connect/token",
    "apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "appSID":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "defaultUserAgent":"Webkit"
}

Documentation for API Endpoints

All URIs are relative to https://api.aspose.cloud/v4.0

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

CONVERSION API

  • For conversion to images allowed formats is jpeg, png, bmp, tiff, gif. Input formats are html, epub, svg.
Class Method Description
Asposehtmlcloud.ConversionApi convertLocalToLocal Convert a document from local disk to a local disk.
Asposehtmlcloud.ConversionApi convertLocalToStorage Convert a document from local disk to user's storage.
Asposehtmlcloud.ConversionApi convertStorageToLocal Convert a document from user's storage to local disk.
Asposehtmlcloud.ConversionApi convertStorageToStorage Convert a document from user's storage to user's storage.
Asposehtmlcloud.ConversionApi convertUrlToLocal Convert the HTML document by URL to local disk.
Asposehtmlcloud.ConversionApi convertUrlToStorage Convert the HTML document by URL to user's storage.
Asposehtmlcloud.ConversionApi convert Convert a document to the specified format.

VECTORIZATION API

Class Method Description
Asposehtmlcloud.VectorizationApi vectorizeLocalToLocal Vectorization an image from local disk to a local disk.
Asposehtmlcloud.VectorizationApi vectorizeLocalToStorage Vectorization an image from local disk to user's storage.
Asposehtmlcloud.VectorizationApi vectorizeStorageToLocal Vectorization an image from user's storage to local disk.
Asposehtmlcloud.VectorizationApi vectorizeStorageToStorage Vectorization an image from user's storage to user's storage.
Asposehtmlcloud.VectorizationApi vectorize Vectorization an image to the specified format.

STORAGE API

Class Method HTTP request Description
Asposehtmlcloud.StorageApi deleteFile DELETE /html/file Delete file
Asposehtmlcloud.StorageApi downloadFile GET /html/file Download file
Asposehtmlcloud.StorageApi uploadFile POST /html/file Upload file
Asposehtmlcloud.StorageApi createFolder POST /html/folder Create the folder
Asposehtmlcloud.StorageApi deleteFolder DELETE /html/folder Delete folder
Asposehtmlcloud.StorageApi getFilesList GET /html/folder Get all files and folders within a folder
Asposehtmlcloud.StorageApi getDiscUsage GET /html/storage/disc Get disc usage
Asposehtmlcloud.StorageApi objectExists GET /html/storage/exist Check if file or folder exists
Asposehtmlcloud.StorageApi storageExists GET /html/storage/exist/storage Check if storage exists

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.

Package Sidebar

Install

npm i @asposecloud/aspose-html-cloud

Weekly Downloads

21

Version

22.12.1

License

MIT

Unpacked Size

15.5 MB

Total Files

75

Last publish

Collaborators

  • saudaspose
  • asposecloud