You can try and test Aspose.Words library in your Java application without purchasing a License
; but, a non-licensed (trial) Aspose.Words for Java API will create Word, XPS, PDF document (and many other supported file formats) with some limitations e.g., following red colored text messages will be injected and all pages produced by Aspose.Words will contain a watermark at the middle:
- In addition to actual content, output document’s body will start with an “Evaluation Only …” paragraph:
"Evaluation Only. Created with Aspose.Words. Copyright 2003-2021 Aspose Pty Ltd."
This text will precisely be injected into Aspose.Words’ DOM hierarchy (Document Object Model) at the following position:
Document | First Section | Body | First Paragraph
- In addition to actual content, “This document was truncated …” red text message will appear at the very end of output document
"This document was truncated here because it was created in the Evaluation Mode."
Its precise position in DOM hierarchy will be:
Document | Last Section | Body | Last Paragraph
- All the pages produced by non-licensed version of Aspose.Words for Java API will be watermarked with logo image of Aspose and this evaluation watermark will appear at the center of each page.
This watermark image will be inserted into Primary Headers of all the Sections of output file. The following DOM structure reflects the location of such watermark Shapes
:
Document | All Sections | Primary Headers | First Paragraphs | 1st Watermark Shapes
- The “Created with an evaluation copy…” red text message will appear at the bottom of every page (inside the Primary Footer stories) of output Word document
"Created with an evaluation copy of Aspose.Words. To discover the full versions of our APIs please visit: https://products.aspose.com/words/"
And here is the exact location of above red paragraph in Aspose.Words’ DOM hierarchical structure:
Document > (All) Sections > Primary Footer Stories > First Paragraphs
- Limits on File Size: This is another constraint when running Aspose.Words for Java in evaluation mode and it restricts output file size to a few hundred paragraphs.
The above evaluation version limitations can be avoided by simply calling either the License.setLicense or the Metered.setMeteredKey method in the startup code of your Java application before actually using any other Aspose.Words classes. The License.setLicense
method requires a License File; you can either purchase one or request for a 30-day Temporary License. You can read more about it in Licensing and Subscription section of Aspose.Words for Java documentation.
Please check for the following points in case you find that the evaluation version limitations are still being imposed in Aspose.Words generated documents even after you added licensing related code at the startup of your Java application:
- Are Permissions for reading/accessing the license (.lic file) granted to your Java application?
- Debug program & step through in the debugger to make sure that a call to
setLicense
orsetMeteredKey
method is actually getting executed. - Have you passed the correct path & license file name into
setLicense
method? In case of wrong path, ‘Aspose.Words for Java’ will throw exception. TheLicense.setLicense()
method will throw IllegalStateException for an invalid, wrong or expired license. So, please place Aspose.Words licensing code inside atry-catch
block to catch such exceptions. - Do not create
Document
class object before executingsetLicense
orsetMeteredKey
method. - Open your license file with Notepad & check its ‘subscription expiry date’. Make sure you are not using a version of ‘Aspose.Words for Java’ that is released after the expiry date of your license.
Validate if Aspose.Words for Java is Licensed or Running in Evaluation/Trial Mode?
Before starting document processing or conversions, it is better to first check if a valid license has already been applied or not. Here are a few ways to validate if Aspose.Words is licensed and running in its full capacity:private static boolean isLicensed() throws Exception {
String testString = "test";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write(testString);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
doc.save(outputStream, SaveFormat.DOCX);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
doc = new Document(inputStream);
String test = doc.toString(SaveFormat.TEXT).trim();
return (doc.toString(SaveFormat.TEXT).trim().equals(testString));
}
Another way is to declare a global variable to determine whether Aspose.Words is running in evaluation mode or not:
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.License;
public class Program {
public static void main(String[] args) throws Exception {
boolean isLicensed = false;
try {
License lic = new License();
lic.setLicense("C:\\path to license file.lic");
isLicensed = true;
} catch (IllegalStateException ex) {
isLicensed = false;
}
if (isLicensed) {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Avoiding Evaluation Only. Created with Aspose.Words. Copyright 2003-2021 Aspose Pty Ltd");
// Lets convert Word document to PDF file
doc.save("C:\\Temp\\conversion from word to.pdf");
} else {
System.out.println("License not applied & 'Aspose.Words for Java' is running in Evaluation mode");
}
}
}
And you can build logic on the following Java code to check the validity of Metered License:
import com.aspose.words.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class Program {
public static void main(String[] args) throws Exception {
String publicKey = "";
String privateKey = "";
boolean isLicensed = false;
try {
Metered m = new Metered();
m.setMeteredKey(publicKey, privateKey); // the license only needs to be set Once
if (isLicensed()) {
System.out.println("License applied. Start processing/conversions ...");
isLicensed = true;
} else {
System.out.println("Something went wrong during licensing. Aspose.Words is now running in trial/evaluation mode");
isLicensed = false;
}
} catch (Exception ex) {
System.out.println("Exception!!!");
isLicensed = false;
}
if (isLicensed) {
System.out.println("license is successfully applied");
Document doc = new Document("C:\\Temp\\word.docx");
doc.save("C:\\Temp\\conversion from Word DOCX to.pdf");
}
System.out.println(("done"));
}
private static boolean isLicensed() throws Exception {
// Use same code snippet as mentioned just under the heading: "Validate if Aspose.Words for Java is Licensed or Running in Evaluation/Trial Mode?"
}
}