As per documentation we are using the following code snippet to set the license, however its not working
try (var byteArrayOutputStream = new ByteArrayOutputStream()) {
com.aspose.words.License licenseaw = new com.aspose.words.License();
// Set the license
try {
final InputStream is = new URL("<URL to the .lic file>").openStream();
licenseaw.setLicense(is);
} catch (Exception e) {
e.printStackTrace();
}
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
builder.insertHtml(htmlString);
document.save(byteArrayOutputStream, SaveFormat.DOCX);
docBytes = byteArrayOutputStream.toByteArray();
}
License.isLicenseSet();
We are using the version 23.8.0
method is not exposed in the class
@farshadpalayil License.isLicenseSet()
method has been removed from Aspose.Words public API a while ago due to security reasons. Usually it is not required to check whether the license is set, since Aspose.Words throws an exception when you attempt to set an invalid license or Aspose.Words cannot find the license file.
If you need to check whether the license is set, you can use code like this:
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 = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write(text);
// 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 = new ByteArrayInputStream(baos.toByteArray());
doc = new Document(inStream);
// Check text of the first paragraph.
return (doc.getFirstSection().getBody().getFirstParagraph().toString(SaveFormat.TEXT).trim().equals(text));
}
catch (Exception ex)
{
// do nothing
}
return false;
}
try (var byteArrayOutputStream = new ByteArrayOutputStream()) {
com.aspose.words.License wordsLic = new com.aspose.words.License();
wordsLic.setLicense("C:\\Projects\\documents\\Aspose.Words.Java.lic");
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
builder.insertHtml(htmlString);
document.save(byteArrayOutputStream, SaveFormat.DOCX);
docBytes = byteArrayOutputStream.toByteArray();
}
We are using the following method and facing the same issue
May the license is invalid
So please validate the license provided
@farshadpalayil What exception is thrown by License.setLicense
? Could you please send the license in private message? We will check it on our side and provide you more information. Also, you can check the following points:
- Make sure your call to
SetLicense
gets executed. Step through in the debugger.
- Make sure your code does not catch an exception thrown by Aspose.Words licensing code. For example, Aspose.Words will throw if it cannot find the license.
- Make sure the input documents do not already have the evaluation message. Aspose.Words does not delete existing evaluation messages.
- Make sure
SetLicense
is executed before you instantiate any Document
object.
@farshadpalayil The provided license works fine with the latest 23.8 version of Aspose.Words for Java.