Aspose for Cloud

This add-on is operated by Aspose for Cloud

Aspose for Cloud add-on for Heroku

Aspose for Cloud

Last Updated: 19 March 2014

The Aspose for Cloud add-on is currently in beta.

Table of Contents

Saaspose is an add-on for providing document automation as a service. Saaspose is the easiest API to create, convert and automate documents in the cloud.

Saaspose’s REST API allows you to add support for all kinds of common tasks to your Heroku web app: document assembly, mail merge, reporting, file conversion, text and image extraction, metadata removal, barcode generation and recognition, email tracking and creation, targeting content to different devices.

Saaspose is accessible via an API and has supported client libraries for .NET, Java, Ruby and PHP.

Installing the add-on

Saaspose addon can be attached to a Heroku application via the CLI:

A list of all plans available can be found here.

$ heroku addons:add saaspose
-----> Adding saaspose to sharp-mountain-4005... done

Once Saaspose has been added a SAASPOSE_URL setting will be available in the app configuration and will contain the canonical URL used to access the newly provisioned Saaspose service instance. This can be confirmed using the heroku config command.

$ heroku config | grep SAASPOSE
SAASPOSE_APPKEY:            12341234123412341234123412341234
SAASPOSE_APPSID:            12341234-1234-1234-1234-123412341234
SAASPOSE_URL:               https://api.saaspose.com/v1.0

The App SID and App Key values are also available from the app configuration.

After installing Saaspose the application should be configured to fully integrate with the add-on.

Using with Java

A Java quickstart guide and example source is available on GitHub and can be seen running at http://saaspose-java.herokuapp.com/.

Saaspose has an SDK for Java which implements the common features like authentication, send request, receive response, storage and other features.

Add the Saaspose SDK for Java as a dependency in your pom.xml file.

<dependency>
        <groupId>com.saaspose</groupId>
        <artifactId>saaspose.sdk</artifactId>
        <version>1.0.0.1</version>
</dependency>

Complete pom.xml file can be downloaded from here.

The sample code to create a barcode is given below.

// Create the barcode and save to local disk
//specify product URI
Product.setBaseProductUri(System.getenv("SAASPOSE_URL"));

//specify App Key and App SID
SaasposeApp.setAPPKEY(System.getenv("SAASPOSE_APPKEY"));
SaasposeApp.setAPPSID(System.getenv("SAASPOSE_APPSID"));

// Create an instance of BarCodeBuilder class
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String codetext = "Heroku test -  " + dateFormat.format(date);
BarCodeBuilder builder = new BarCodeBuilder(codetext, BarCodeType.Pdf417);
// Save to server
GenerationResponse response = builder.Save(
        SaveLocation.Local, "barcode.png", ImageFormat.PNG);

Using with Python

A Python quickstart guide and example source is available on GitHub and can be seen running at http://saaspose-python.herokuapp.com/.

Currently there is no SDK for Python. But the add-on can easily be used with Python because Saaspose is a REST API can be used in any language/platform that can send and receive web request (XML/JSON formats). The necessary methods for authentication and response parsing are included with the sample application in the form of Saaspose.Common package.

The sample code for getting properties of a Word document would be

def docProperties():
        # Initialize the URI, App key and SID
        Product.BaseProductUri = os.environ.get('SAASPOSE_URL', '')
        SaasposeApp.APPKEY = os.environ.get('SAASPOSE_APPKEY', '')
        SaasposeApp.APPSID = os.environ.get('SAASPOSE_APPSID', '')

        responseText = "2. Saaspose.Words<br/><hr/>"
        responseText = responseText + "Sending request to Saaspose for reading document properties....<br/>"

        # Set the file name on Saaspose storage which we want to read
        filename = "DinnerInvitation.docx"

        # Build the URI for sending request
        uri = Product.BaseProductUri + "/words/"
        # Add the file name of Word document
        uri = uri + filename
        # resource
        uri = uri + "/documentproperties"
        # folder
        uri = uri + "?folder="

        # Get the json response
        result = Utils.processCommand(uri, 'GET')
        data = json.loads(result)

        responseText = responseText + "response received.<br/>"

        # Parse the response
        responseText = responseText + "Response from Saaspose: <br/>"
        responseText = responseText + 'Status: ' + data['Status'] + "<br/>"
        responseText = responseText + 'Code: ' + str(data['Code']) + "<br/>"

        responseText = responseText + "<br/>Document properties:<br/>"
        for item in data['DocumentProperties']['List']:
                responseText = responseText + item['Name'] + ': ' + str(item['Value']) + "<br/>"

        responseText = responseText + "<br/><br/>"

        return responseText

Using with Ruby

A Ruby quickstart guide and example source is available on GitHub and can be seen running at http://saaspose-ruby.herokuapp.com/.

Currently, work on the Ruby SDK is in progress. Only few features of each product are implemented. But we can still use the Saaspose REST API to utilize ALL the features that Saaspose products offer. The necessary methods for authentication and response parsing etc are implemented as Ruby Gem. This gem is required in our sample application.

In Gemfile, add the following lines to include the Saaspose SDK gem and dependencies.

gem 'saasposesdk'
gem 'rest-client'
gem 'mime-types'

The sample code for getting properties of a Word document would be

# Set the Saaspose APPSID and App key
Common::Product.setBaseProductUri(ENV['SAASPOSE_URL'])
Common::SaasposeApp.new(ENV['SAASPOSE_APPSID'], ENV['SAASPOSE_APPKEY'])

# Get document properties using Saaspose.Words
docFileName = 'DinnerInvitation.docx'
urlDoc = $productURI + '/words/' + docFileName + '/documentproperties?folder='
signedURL = Common::Utils.sign(urlDoc)
responseWords = RestClient.get(signedURL, :accept => 'application/json')
data = JSON.parse(responseWords.body)
@responseWords = 'Status: ' + data['Status'] + "<br>"
@responseWords = @responseWords + 'Code: ' + data['Code'].to_s + "<br>"
@responseWords = @responseWords + "<br/>Document properties:<br/>"
data['DocumentProperties']['List'].each do |item|
        @responseWords = @responseWords + item['Name'] + ': ' + item['Value'].to_s + "<br/>"
end

Removing the add-on

Saaspose can be removed via the CLI.

This will destroy all associated data and cannot be undone!

$ heroku addons:remove saaspose
-----> Removing saaspose from sharp-mountain-4005... done, v20 (free)

Support

All Saaspose support and runtime issues should be submitted via on of the Heroku Support channels. Any non-support related issues or product feedback is welcome at support@saaspose.com.