Validating license for Aspose.pdf for Java

Hello,

I’m triying to validate the license aspose.pdf for java following the page: https://docs.aspose.com/display/pdfjava/Applying+a+License#ApplyingaLicense-ValidatetheLicense :

License license = new License();
license.setLicense("Aspose.Pdf.Java.lic");
 
if (License.isLicensed()) {
    System.out.println("License is Set!");
} 

But it dosent work because I dont see the operation “isLicensed” in the classe License (static or non static operation), and i dident find it in the java code License | Aspose.PDF for Java API Reference

My version is 17.10.0.

Can you please tell me how can I validate my License.

Thanks for your help.

Hello,

The documentation https://docs.aspose.com/display/pdfjava/Applying+a+License#ApplyingaLicense-ValidatetheLicense was updated :

License license = new License();
license.setLicense(“Aspose.Pdf.Java.lic”);

if (com.aspose.pdf.Document.isLicensed()) {
System.out.println(“License is Set!”);
}

Thanks for your help.
Best regards.

@mygreffe

I have observed your comments and like to share with you that isLicensed method was moved to Document class, as updated in the documentation. We are glad to know that your issue is now resolved. Please feel free to contact us if you need any assistance with our APIs. We will be glad to help.

Hi Team,
How to verify an expired license.
It was all good, until I tested with an expired license. I receive exception with the message.

Below code verifies the license credibility,
if (com.aspose.pdf.Document.isLicensed()) {
System.out.println(“License is Set!”);
}
I accept.

When I test the expired License, error hits at below 2nd Line(.setLicense(“Aspose.Pdf.Java.lic”)). So how to handle this exception.

Line 1 : License license = new License();
Line 2 : license.setLicense(“Aspose.Pdf.Java.lic”);

I get below run time exception

java.lang.IllegalStateException: The license is not valid for this product. For free technical support, please post this error and the file in the Aspose.PDF Forums Aspose.PDF Product Family - Free Support Forum - aspose.com
at com.aspose.pdf.l9l.lI(Unknown Source)
at com.aspose.pdf.l9l.lI(Unknown Source)
at com.aspose.pdf.License.setLicense(Unknown Source)
at com.hcl.ers.atlas.image.processing.pdf.WriteChartIntoPDFAspose.validateLicenseAspose(WriteChartIntoPDFAspose.java:82)
at com.hcl.ers.atlas.image.processing.pdf.WriteChartIntoPDFAspose.insertBookMarkInToPdfAspose(WriteChartIntoPDFAspose.java:367)
at com.hcl.ers.atlas.image.processing.pdf.WriteChartIntoPDFAspose.main(WriteChartIntoPDFAspose.java:64)

@HAREEM_HCL_COM

You may surround the setLicense method in a try-catch block and then validate the license in try block so that your program executes only when the credibility/validity of license is verified.

try{
    com.aspose.pdf.License PDFlicense = new com.aspose.pdf.License();
    PDFlicense.setLicense("Path");

        if (com.aspose.pdf.Document.isLicensed()) {
        System.out.println("License is Set!");

        //TODO Code Here
        }
        else
        {
            System.out.println("License is NOT Set!");
        }
    }
catch (Exception ex)
{
    ex.printStackTrace();
}

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

I have handled the exception already. Throwing expection is is not good code standard, is in’t it.
Though code continues to next step, exception at Runtime and tracking the validation at exception doesn’t seem to a good coding standard.

Another problem.
To verify license expiration, i placed an expired license file to test it. Now when I place the purchased license file, it is still gives below error.

java.lang.IllegalStateException: The license is not valid for this product. For free technical support, please post this error and the file in the Aspose.PDF Forums Aspose.PDF Product Family - Free Support Forum - aspose.com
at com.aspose.pdf.l9l.lI(Unknown Source)
at com.aspose.pdf.l9l.lI(Unknown Source)
at com.aspose.pdf.License.setLicense(Unknown Source)
at com.hcl.ers.atlas.image.processing.pdf.WriteChartIntoPDFAspose.validateLicenseAspose(WriteChartIntoPDFAspose.java:86)
at com.hcl.ers.atlas.image.processing.pdf.WriteChartIntoPDFAspose.writeChartToPdfAspose(WriteChartIntoPDFAspose.java:188)
at com.hcl.ers.atlas.image.processing.pdf.WriteChartIntoPDFAspose.main(WriteChartIntoPDFAspose.java:65)

@HAREEM_HCL_COM

We are glad to know that you have been able to handle the exception as per your requirements. Moreover, can you please try to clean and build the project if that resolves the problem. In case you still face the issue then share your license with us via message by clicking on my username and then message icon so that we may investigate and assist you accordingly.