19.7.0 • Published 5 years ago

asposehtmlcloud v19.7.0

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Asposehtmlcloud

Asposehtmlcloud - JavaScript client for asposehtmlcloud

  • API version: 19.7.0
  • Package version: 19.7.0

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

Example:

var conf = {
    "basePath":"https://api.aspose.cloud/v3.0",
    "authPath":"https://api.aspose.cloud/connect/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.

var conf = {
    "basePath":"https://api.aspose.cloud/v3.0",
    "authPath":"https://api.aspose.cloud/connect/token",
    "apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "appSID":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "testResult":"/testresult/",
    "testData":"/testdata/",
    "remoteFolder":"HtmlTestDoc/",
    "defaultUserAgent":"Webkit"
};

//Create storage api for upload to server
var api = require('asposehtmlcloud');
var fs = require('fs');
var storageApi = new api.StorageApi(conf);


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

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


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
var opts = {versionId:versionId, storage:null};

storageApi.uploadFile(folder + "/" + filename, file, opts, 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.
  'resolution': 300, // {Number} 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);
  }
};
conversionApi.GetConvertDocumentToImage(filename, outFormat, opts, callback);

Documentation for API Endpoints

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

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

HTML API

  • For conversion to images allowed formats is jpeg, png, bmp, tiff, gif. Input formats are html, epub, svg.
ClassMethodHTTP requestDescription
Asposehtmlcloud.ConversionApiGetConvertDocumentToImageGET /html/{name}/convert/image/{outFormat}Convert the HTML document from the storage by its name to the specified image format.
Asposehtmlcloud.ConversionApiGetConvertDocumentToImageByUrlGET /html/convert/image/{outFormat}Convert the HTML page from the web by its URL to the specified image format.
Asposehtmlcloud.ConversionApiGetConvertDocumentToPdfGET /html/{name}/convert/pdfConvert the HTML document from the storage by its name to PDF.
Asposehtmlcloud.ConversionApiGetConvertDocumentToPdfByUrlGET /html/convert/pdfConvert the HTML page from the web by its URL to PDF.
Asposehtmlcloud.ConversionApiGetConvertDocumentToXpsGET /html/{name}/convert/xpsConvert the HTML document from the storage by its name to XPS.
Asposehtmlcloud.ConversionApiGetConvertDocumentToXpsByUrlGET /html/convert/xpsConvert the HTML page from the web by its URL to XPS.
Asposehtmlcloud.ConversionApiPostConvertDocumentInRequestToImagePOST /html/convert/image/{outFormat}Converts the HTML document (in request content) to the specified image format and uploads resulting file to storage.
Asposehtmlcloud.ConversionApiPostConvertDocumentInRequestToPdfPOST /html/convert/pdfConverts the HTML document (in request content) to PDF and uploads resulting file to storage.
Asposehtmlcloud.ConversionApiPostConvertDocumentInRequestToXpsPOST /html/convert/xpsConverts the HTML document (in request content) to XPS and uploads resulting file to storage.
Asposehtmlcloud.ConversionApiPutConvertDocumentToImagePUT /html/{name}/convert/image/{outFormat}Converts the HTML document (located on storage) to the specified image format and uploads resulting file to storage.
Asposehtmlcloud.ConversionApiPutConvertDocumentToPdfPUT /html/{name}/convert/pdfConverts the HTML document (located on storage) to PDF and uploads resulting file to storage.
Asposehtmlcloud.ConversionApiPutConvertDocumentToXpsPUT /html/{name}/convert/xpsConverts the HTML document (located on storage) to XPS and uploads resulting file to storage.
Asposehtmlcloud.ConversionApiGetConvertDocumentToMHTMLByUrlGET /html/convert/mhtmlConverts the HTML page from Web by its URL to MHTML returns resulting file in response content.
Asposehtmlcloud.ConversionApiGetConvertDocumentToMarkdownGET /html/{name}/convert/mdConverts the HTML document (located on storage) to Markdown and returns resulting file in response content.
Asposehtmlcloud.ConversionApiPostConvertDocumentInRequestToMarkdownPOST /html/convert/mdConverts the HTML document (in request content) to Markdown and uploads resulting file to storage by specified path.
Asposehtmlcloud.ConversionApiPutConvertDocumentToMarkdownPUT /html/{name}/convert/mdConverts the HTML document (located on storage) to Markdown and uploads resulting file to storage by specified path.
Asposehtmlcloud.ImportApiGetConvertMarkdownToHtmlGET /html/{name}/import/mdConverts the Markdown document (located on storage) to HTML and returns resulting file in response content.
Asposehtmlcloud.ImportApiPostConvertMarkdownInRequestToHtmlPOST /html/import/mdConverts the Markdown document (in request content) to HTML and uploads resulting file to storage by specified path.
Asposehtmlcloud.ImportApiPutConvertMarkdownToHtmlPUT /html/{name}/import/mdConverts the Markdown document (located on storage) to HTML and uploads resulting file to storage by specified path.
Asposehtmlcloud.DocumentApiGetDocumentByUrlGET /html/downloadReturn all HTML page with linked resources packaged as a ZIP archive by the source page URL.
Asposehtmlcloud.DocumentApiGetDocumentFragmentByXPathGET /html/{name}/fragments/{outFormat}Return list of HTML fragments matching the specified XPath query.
Asposehtmlcloud.DocumentApiGetDocumentFragmentByXPathByUrlGET /html/fragments/{outFormat}Return list of HTML fragments matching the specified XPath query by the source page URL.
Asposehtmlcloud.DocumentApiGetDocumentFragmentsByCSSSelectorGET /html/{name}/fragments/css/{outFormat}Return list of HTML fragments matching the specified CSS selector.
Asposehtmlcloud.DocumentApiGetDocumentFragmentsByCSSSelectorByUrlGET /html/fragments/css/{outFormat}Return list of HTML fragments matching the specified CSS selector by the source page URL.
Asposehtmlcloud.DocumentApiGetDocumentImagesGET /html/{name}/images/allReturn all HTML document images packaged as a ZIP archive.
Asposehtmlcloud.DocumentApiGetDocumentImagesByUrlGET /html/images/allReturn all HTML page images packaged as a ZIP archive by the source page URL.
Asposehtmlcloud.TemplateMergeApiGetMergeHtmlTemplateGET /html/{templateName}/mergePopulate HTML document template with data located as a file in the storage.
Asposehtmlcloud.TemplateMergeApiPostMergeHtmlTemplatePOST /html/{templateName}/mergePopulate HTML document template with data from the request body. Result document will be saved to storage.

STORAGE API

ClassMethodHTTP requestDescription
Asposehtmlcloud.StorageApicopyFilePUT /html/storage/file/copy/{srcPath}Copy file
Asposehtmlcloud.StorageApideleteFileDELETE /html/storage/file/{path}Delete file
Asposehtmlcloud.StorageApidownloadFileGET /html/storage/file/{path}Download file
Asposehtmlcloud.StorageApimoveFilePUT /html/storage/file/move/{srcPath}Move file
Asposehtmlcloud.StorageApiuploadFilePUT /html/storage/file/{path}Upload file
Asposehtmlcloud.StorageApicopyFolderPUT /html/storage/folder/copy/{srcPath}Copy folder
Asposehtmlcloud.StorageApicreateFolderPUT /html/storage/folder/{path}Create the folder
Asposehtmlcloud.StorageApideleteFolderDELETE /html/storage/folder/{path}Delete folder
Asposehtmlcloud.StorageApigetFilesListGET /html/storage/folder/{path}Get all files and folders within a folder
Asposehtmlcloud.StorageApimoveFolderPUT /html/storage/folder/move/{srcPath}Move folder
Asposehtmlcloud.StorageApigetDiscUsageGET /html/storage/discGet disc usage
Asposehtmlcloud.StorageApigetFileVersionsGET /html/storage/version/{path}Get file versions
Asposehtmlcloud.StorageApiobjectExistsGET /html/storage/exist/{path}Check if file or folder exists
Asposehtmlcloud.StorageApistorageExistsGET /html/storage/{storageName}/existCheck 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:

19.7.0

5 years ago

19.6.2

5 years ago

19.6.1

5 years ago

19.6.0

5 years ago

19.5.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago