We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Words for java : How to handle expiration of license programmatically

I am trying to provide an automate healthcheck for my service that uses Aspose words for java.

Currently I am trying to look for way this state of the library can be identified. Is there an exception that gets thrown that uniquely identifies this state ?

I was told by the online chat support people (aspose ) that I can use IllegalStateException. However upon digging more I find that that error may also get triggered when wrongful conversion is reqeusted or improper document is presented for conversion.

Does anyone have any thoughts on this ?

Hi Sharadha,

Thanks for your inquiry. Yes, in this case, Aspose.Words fro Java will throw similar to the following error:

java.lang.IllegalStateException: The subscription included in this license allows free upgrades until 04 Dec 2013, but this version of the product was released on 31 May 2014. Please renew the subscription or use a previous version of the product.

Secondly, I am afraid, the License class doesn’t expose any built-in methods to check/track the status whether a license is properly applied or not. However, if you want to be sure, you can try creating your own custom method to do this job. To do this you could create a blank document and export this to a stream. Then reload this and check the first paragraph in the body for the evaluation message. Please see the following code:
License license = new License();
Document doc = null;

try {
license.setLicense(getMyDir() + “Aspose.Words.lic”);
} catch (Exception ex) {
// do nothing

if (isLicenseSet()) {
System.out.println(“License is applied. You are good to go”);
} else {
System.out.println(“Something wrong with License”);

private static boolean isLicenseSet() {
try {
// We will insert this text at the beggining of the document.
// If the license set this text will be in th efirt paragraph,
// if not an evaluation watermark will be in the first paragraph.
String text = “This is text used to check if the license is set”;
    Document doc <font color="BLUE">=</font> <font color="RED">new</font> Document<font color="BLUE">(</font><font color="BLUE">)</font><font color="BLUE">;</font>
    DocumentBuilder builder <font color="BLUE">=</font> <font color="RED">new</font> DocumentBuilder<font color="BLUE">(</font>doc<font color="BLUE">)</font><font color="BLUE">;</font>
    builder<font color="BLUE">.</font>write<font color="BLUE">(</font>text<font color="BLUE">)</font><font color="BLUE">;</font>

    <font color="GREEN"><i>// Save and open the document. If Aspose.Words works in evaluation mode it will add a watermark.

ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.DOC);

    InputStream inStream <font color="BLUE">=</font> <font color="RED">new</font> ByteArrayInputStream<font color="BLUE">(</font>baos<font color="BLUE">.</font>toByteArray<font color="BLUE">(</font><font color="BLUE">)</font><font color="BLUE">)</font><font color="BLUE">;</font>
    doc <font color="BLUE">=</font> <font color="RED">new</font> Document<font color="BLUE">(</font>inStream<font color="BLUE">)</font><font color="BLUE">;</font>

    <font color="GREEN"><i>// Check text of the first paragraph.

return (doc.getFirstSection().getBody().getFirstParagraph().toString(SaveFormat.TEXT).trim().equals(text));
} catch (Exception ex) {
// do nothing

<font color="RED">return</font> false<font color="BLUE">;</font>


I hope, this helps.

Best regards,