Azure Functions - Set Aspose License


#1

Hi Team,

We are trying to implement aspose in Azure Functions and we are finding Hard time to set the License. We have placed the “Aspose.Total.Product.Family.lic” in Azure Storage and trying to read them using Stream.
This is the function to read License from Azure Storage and Set it for Aspose Words. This works fine without throwing any exception. Howvever the rendered doc shows Evaluation watermark.

@FunctionName(“BlobDownload-ReadWordLicense”)
public void run3(@HttpTrigger(name = “req”, methods = { HttpMethod.GET,
HttpMethod.POST }, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional> request,
final ExecutionContext context) {
context.getLogger().info(“Java HTTP trigger processed a request.”);

  try {
  	com.aspose.words.License license = new com.aspose.words.License();
  	
  	CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
  	CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
  	
  	CloudBlobContainer container = blobClient.getContainerReference("doccontainer");
  	
  	
  	CloudBlockBlob asposeLicense = container.getBlockBlobReference("Aspose.Total.Product.Family.lic");
  	InputStream asposeLicensestream = asposeLicense.openInputStream();
  	
  	
  	context.getLogger().info("Extracted License For Aspose");
  	license.setLicense(asposeLicensestream);
  	context.getLogger().info("Applied License For Aspose");
  	
  				
  } catch (Exception e) {
  	StringWriter errors = new StringWriter();
  	e.printStackTrace(new PrintWriter(errors));
  	context.getLogger().info(errors.toString());
  }

}

But If we use the same code to set the License for Aspose PDF we receive the below Exception

@FunctionName(“BlobDownload-ReadPdfLicense”)
public void run4(@HttpTrigger(name = “req”, methods = { HttpMethod.GET,
HttpMethod.POST }, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional> request,
final ExecutionContext context) {
context.getLogger().info(“Java HTTP trigger processed a request.”);

  try {
  	com.aspose.pdf.License license = new com.aspose.pdf.License();
  	
  	CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
  	CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
  	
  	CloudBlobContainer container = blobClient.getContainerReference("doccontainer");
  	
  	
  	CloudBlockBlob asposeLicense = container.getBlockBlobReference("Aspose.Total.Product.Family.lic");
  	InputStream instream = asposeLicense.openInputStream();
  	context.getLogger().info("Extracted License For Aspose");
  	license.setLicense(instream);
  	context.getLogger().info("Applied License For Aspose");
  	
  				
  } catch (Exception e) {
  	StringWriter errors = new StringWriter();
  	e.printStackTrace(new PrintWriter(errors));
  	context.getLogger().info(errors.toString());
  }

}

Exception:

image.png (9.7 KB)

This Looks totally weird. Please let us know How to set the License properly inside azure functions.

By the way, We are using Java platform and not .NET

I have also attached the project for your reference

Thanks,
Prasanna Shanmuganathan


#2

@pshanmuganathan

Thank you for contacting support.

You may verify if the license has been set for Aspose.Words for Java API with below code:

        License license = new License();
        license.setLicense(path);
        if (license.isLicensed()) {
        System.out.println(“License is Set!”);
        }

Moreover, you may share the sample project via Google Drive, Dropbox etc. if the file size exceeds forum attachment limit, 3MB. Also share your license file for our reference.


#3

Hi Farhan,

I think you did not get my question. The code you have given above is setting license from a normal path. I am aware of it and it works when my application runs on a server. But I want to know how to set the License in a serverless environment like Azure Functions. I do not have a path to place the file and refer the path in set License. Hope you get my question.

Please let me know how to set license inside an azure function
Thanks,
Prasanna Shanmuganathan


#4

@pshanmuganathan

Please note that we have suggested to validate your license with isLicensed property so that setting of license for Aspose.Words for Java may be verified. Moreover, like other Aspose APIs, Aspose.PDF for Java API also allows Setting License from Stream Object. You may access the files in your Azure Storage and create a FileInputStream object to use the file for setting license; or you may apply any other file handling approach from Azure Storage as per your requirements.


#5

Hi Farhan,

Thanks for your reply, but please help me addressing the below issue ,

I was able to read the License from Azure Storage and opened in a stream to set License. This works fine for Aspose.Words. However I am using the same code to set license for pdf but the below exception is thrown. Looks totally weird

For Word Code,

com.aspose.words.License license = new com.aspose.words.License();
CloudBlockBlob asposeLicense = container.getBlockBlobReference(“Aspose.Total.Product.Family.lic”);
InputStream inputStream = asposeLicense.openInputStream();
inputStream.reset();
license.setLicense(inputStream);

The above code works totally fine.

Same Pdf code ,

com.aspose.pdf.License license = new com.aspose.pdf.License ();
CloudBlockBlob asposeLicense = container.getBlockBlobReference(“Aspose.Total.Product.Family.lic”);
InputStream inputStream = asposeLicense.openInputStream();
inputStream.reset();
license.setLicense(inputStream);

The above pdf throws the below exception

[Fatal Error] :1:1: Premature end of file.
Exception in thread "main" org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
	at com.aspose.pdf.l9l.lI(Unknown Source)
	at com.aspose.pdf.License.setLicense(Unknown Source)
	at opsDoc.DocDownload.App.main(App.java:58)

And I am not using the same InputStream. Consider them as two different programs. One I am using Aspose PDF java and other I am using ASPOSE Word for Java. Setting License on Aspose.Words works properly but with ASPOSE.pdf setting License throws Exception
Please help me in Resolving this.

Thanks,
Prasanna Shanmuganathan


#6

@pshanmuganathan

Would you please share your license file and a sample application with us, so that we may reproduce and investigate it in our environment to help you out.