Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

GitHub license GitHub last commit

HTML Rendering & Conversion Android Cloud REST API

Aspose.HTML Cloud for android is a programming SDK that allows software developers to manipulate and convert HTML documents from within their own applications. A Wrapper of RESTful APIs, Aspose.HTML Cloud for Android/Java speeds up HTML programming and conversion. This cloud SDK assists to develop cloud-based HTML page rendering, processing, translation & conversion apps in Android & Java via REST API.

HTML Processing Features

  • Fetch the HTML page along with its resources as a ZIP archive by providing the page URL.
  • Based on page URL, retrieve all images of an HTML page as a ZIP package.
  • Load data from a local file to populate the HTML document template.
  • Use the request body to populate the HTML document template.
  • Convert HTML page to numerous other file formats.

Read & Write HTML Formats

HTML, XHTML, zipped HTML, zipped XHTML, MHTML, HTML containing SVG markup, Markdown, JSON

Save HTML As

Fixed Layout: PDF, XPS Images: TIFF, JPEG, PNG, BMP, GIF Other: TXT, ZIP (images)

Read HTML Formats

eBook: EPUB Other: XML, SVG

Enhancements Version 20.11

  • New generation of Aspose.HTML Cloud SDK for .NET (C#) is provided.
  • This version of SDK has been redesigned from scratch being based on the new Aspose.HTML Cloud REST API (v3.0).
  • Currently, it provides only the conversion feature. Other features that are still available in the versions up to v.20.08 are planned to be implemented in this SDK later.
  • Conversion interface provides a more flexible conversion parameters setup.
  • Redesigned storage access is provided using SDK entry point HtmlApi.Storage.
  • Availability of synchronous and asynchronous file upload and download methods.
  • Asynchronous download provides the ability to get progress data for the longer downloads.

How to use the SDK?

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

This project includes:

  • Android dummy application - "/app"
  • Module "html" - this SDK in "/aspose-html-cloud-android"

Prerequisites

To use Aspose HTML for Cloud Android 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

Get ready package or build from source.

Maven users

Add this dependency to your project's POM:

<repositories>
    ...
	<repository>
		<id>AsposeJavaAPI</id>
		<name>Aspose Java API</name>
		<url>https://repository.aspose.cloud/repo/</url>
	</repository>
	...
</repositories>

<dependencies>
     ...
	<dependency>
		<groupId>com.aspose</groupId>
		<artifactId>aspose-html-cloud-android</artifactId>
		<version>20.7.0</version>
		<scope>compile</scope>
	</dependency>
	...
</dependencies>

Building the API client library requires Gradle Build Tool to be installed.

To build the API client library, simply execute:

gradlew.bat build -x test //skip tests

To run test from command string:

gradlew.bat test

Sample usage

The examples below show how your application have to initiate and convert url to image using Aspose.HTML Cloud library:

package com.aspose.test_package;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.aspose.html.ApiClient;
import com.aspose.html.Configuration;
import com.aspose.html.api.ConversionApi;
import com.aspose.html.api.StorageApi;
import com.aspose.html.model.FilesUploadResult;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

public class App {

    // Helper method save the response body to the destination directory
    public static long saveToDisc(ResponseBody body, String fileName) {

        File savedFile = new File(Configuration.getTestDstDir() + File.separator + fileName);
        long fileSizeDownloaded = 0;

        try (InputStream inputStream = body.byteStream();
             OutputStream outputStream = new FileOutputStream(savedFile))
        {
            byte[] fileReader = new byte[4096];

            while (true) {
                int read = inputStream.read(fileReader);
                if (read == -1) break;

                outputStream.write(fileReader, 0, read);
                fileSizeDownloaded += read;
            }
            outputStream.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return fileSizeDownloaded;
    }

    public static void main(String[] args) {

// Get keys from aspose site.
// There is free quota available.
// For more details, see https://purchase.aspose.cloud/pricing

        Configuration.setAPI_KEY("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        Configuration.setAPP_SID("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
        Configuration.setBasePath("https://api.aspose.cloud/v3.0");
        Configuration.setAuthPath("https://api.aspose.cloud/connect/token");
        Configuration.setUserAgent("WebKit");
        Configuration.setDebug(true);
        Configuration.setTestSrcDir("testdata");
        Configuration.setTestDstDir("testresult");

        String name = "test.html";// Document name. Place the html document in the folder "testdata".
        String outFormat = "jpg"; // Convert to jpg
        Integer width = 800; // Resulting image width.
        Integer height = 1000; // Resulting image height.
        Integer leftMargin = 10; // Left resulting image margin.
        Integer rightMargin = 10; // Right resulting image margin.
        Integer topMargin = 10; // Top resulting image margin.
        Integer bottomMargin = 10; // Bottom resulting image margin.
        Integer resolution = 300; // Resolution of resulting image.
        String folder = "/"; // The folder in the storage. Should exist.
        String storage = null; // Name of the storage. null

        // Creating API for need operations
        ConversionApi conversionApi = new ApiClient().createService(ConversionApi.class);
        StorageApi storageApi = new ApiClient().createService(StorageApi.class);


        try {

            // Upload file to storage
            // Test file in the "/testdata" folder in the root of the project
            File f = new File(Configuration.getTestSrcDir(), name);

            if(!f.exists()) {
                System.out.println("file not found");
                throw new RuntimeException("Test file not found");
            }

            RequestBody requestBody = RequestBody.create( MediaType.parse("multipart/form-data"), f);
            MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", f.getName(), requestBody);

            // Upload document to storage
            Call<FilesUploadResult> callUpload = storageApi.uploadFile(folder + File.separator + name, fileToUpload, null);
            Response<FilesUploadResult> res = callUpload.execute();
            System.out.println("Executed is successful = " + res.isSuccessful());  

            // Prepare call execute
            Call<ResponseBody> call = conversionApi.GetConvertDocumentToImage(name, outFormat, width, height, leftMargin, rightMargin, topMargin, bottomMargin, resolution, folder, storage);

            // Execute request
            Response<ResponseBody> img = call.execute();

            // Get body from response
            ResponseBody answer = img.body();

            // Save to test directory
            long result = saveToDisc(answer, "test.zip");
            System.out.println("Result size = " + result);

            } catch (IOException e) {
                e.printStackTrace();
            }
     }
}

Documentation for API Endpoints

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

ConversionApi (INPUT FORMAT: html, epub, swg OUTPUT FORMAT FOR IMAGES: jpeg, bmp, tiff, png, gif)

Method HTTP request Description
GetConvertDocumentToImage GET /html/{name}/convert/image/{outFormat} Convert the HTML document from the storage by its name to the specified image format.
GetConvertDocumentToImageByUrl GET /html/convert/image/{outFormat} Convert the HTML page from the web by its URL to the specified image format.
GetConvertDocumentToPdf GET /html/{name}/convert/pdf Convert the HTML document from the storage by its name to PDF.
GetConvertDocumentToPdfByUrl GET /html/convert/pdf Convert the HTML page from the web by its URL to PDF.
GetConvertDocumentToXps GET /html/{name}/convert/xps Convert the HTML document from the storage by its name to XPS.
GetConvertDocumentToXpsByUrl GET /html/convert/xps Convert the HTML page from the web by its URL to XPS.
PostConvertDocumentInRequestToImage POST /html/convert/image/{outFormat} Converts the HTML document (in request content) to the specified image format and uploads resulting file to storage.
PostConvertDocumentInRequestToPdf POST /html/convert/pdf Converts the HTML document (in request content) to PDF and uploads resulting file to storage.
PostConvertDocumentInRequestToXps POST /html/convert/xps Converts the HTML document (in request content) to XPS and uploads resulting file to storage.
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.
PutConvertDocumentToPdf PUT /html/{name}/convert/pdf Converts the HTML document (located on storage) to PDF and uploads resulting file to storage.
PutConvertDocumentToXps PUT /html/{name}/convert/xps Converts the HTML document (located on storage) to XPS and uploads resulting file to storage.
GetConvertDocumentToMHTMLByUrl GET /html/convert/mhtml Converts the HTML page from Web by its URL to MHTML returns resulting file in response content.
content.
GetConvertDocumentToMarkdown GET /html/{name}/convert/md Converts the HTML document (located on storage) to Markdown and returns resulting file in response content.
PostConvertDocumentInRequestToMarkdown POST /html/convert/md Converts the HTML document (in request content) to Markdown and uploads resulting file to storage by specified path.
PutConvertDocumentToMarkdown PUT /html/{name}/convert/md Converts the HTML document (located on storage) to Markdown and uploads resulting file to storage by specified path.

ImportApi

Method HTTP request Description
GetConvertMarkdownToHtml GET /html/{name}/import/md Converts the Markdown document (located on storage) to HTML and returns resulting file in response content.
PostConvertMarkdownInRequestToHtml POST /html/import/md Converts the Markdown document (in request content) to HTML and uploads resulting file to storage by specified path.
PutConvertMarkdownToHtml PUT /html/{name}/import/md Converts the Markdown document (located on storage) to HTML and uploads resulting file to storage by specified path.

DocumentApi

Method HTTP request Description
GetDocumentByUrl GET /html/download Return all HTML page with linked resources packaged as a ZIP archive by the source page URL.
GetDocumentFragmentByXPath GET /html/{name}/fragments/{outFormat} Return list of HTML fragments matching the specified XPath query.
GetDocumentFragmentByXPathByUrl GET /html/fragments/{outFormat} Return list of HTML fragments matching the specified XPath query by the source page URL.
GetDocumentFragmentsByCSSSelector GET /html/{name}/fragments/css/{outFormat} Return list of HTML fragments matching the specified CSS selector.
GetDocumentFragmentsByCSSSelectorByUrl GET /html/fragments/css/{outFormat} Return list of HTML fragments matching the specified CSS selector by the source page URL.
GetDocumentImages GET /html/{name}/images/all Return all HTML document images packaged as a ZIP archive.
GetDocumentImagesByUrl GET /html/images/all Return all HTML page images packaged as a ZIP archive by the source page URL.

TemplateMergeApi

Method HTTP request Description
GetMergeHtmlTemplate GET /html/{templateName}/merge Populate HTML document template with data located as a file in the storage.
PostMergeHtmlTemplate POST /html/{templateName}/merge Populate HTML document template with data from the request body. Result document will be saved to storage.

SeoApi

Method HTTP request Description
GetSeoWarning GET /html/seo Page analysis and return of SEO warnings.
GetHtmlWarning GET /html/validator Checks the markup validity of Web documents in HTML, XHTML, etc.

StorageApi

Method HTTP request Description
downloadFile GET /html/storage/file/{path} Download file from storage.
uploadFile PUT /html/storage/file/{path} Upload file to storage.
moveFile PUT /html/storage/file/move/{srcPath} Move file in storage.
deleteFile DELETE /html/storage/file/{path} Delete file in the storage.
createFolder PUT /html/storage/folder/{path} Create the folder in the storage.
moveFolder PUT /html/storage/folder/move/{srcPath} Move folder in the storage.
deleteFolder DELETE /html/storage/folder/{path} Delete folder in the storage.
getFilesList GET /html/storage/folder/{path} Get all files and folders within a folder.
getDiscUsage GET /html/storage/disc Get disc usage in the storage.
objectExists GET /html/storage/exist/{path} Check if file or folder exists.
storageExists GET /html/storage/{storageName}/exist Check if storage exists.
getFileVersions GET /html/storage/version/{path} Get file versions in the storage.

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

Docs Full javadoc for Aspose.HTML Api SDK

Aspose.HTML Cloud SDKs in Popular Languages

.NET Java PHP Python Ruby Node.js Android Swift C++ Go
GitHub GitHub GitHub GitHub GitHub GitHub GitHub GitHub GitHub GitHub
NuGet Maven Composer PIP GEM NPM Maven Cocoapods NuGet Go.Dev

Product Page | Documentation | API Reference | Code Samples | Blog | Free Support | Free Trial

About

Java/Android library for communicating with the Aspose.HTML Cloud API

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.