Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/924175f7cb26fdc87f82066843ae7dd6 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/924175f7cb26fdc87f82066843ae7dd6 to your computer and use it in GitHub Desktop.
Installing and clearing the license for the Aspose.Font for Java library

Licensing Examples

Status

Three TestNG tests are implemented and verified with Aspose.Font for Java 26.8:

  • Apply a license from a file: Example-SetLicenseFromFile.java.
  • Apply a license from a stream: Example-SetLicenseFromStream.java.
  • Clear a license: Example-ClearLicense.java.

The file and stream examples come from the Java licensing documentation. The clear-license example follows the .NET test category and the Java License API.

Running the examples

From the examples repository root:

mvn -f src/Aspose.Font.Java/pom.xml -Dtest=LicensingTests -Dgroups=LicensingExamples test

Provide a valid license at tests-data/licenses/Aspose.Font.Java.lic and these test fonts:

  • tests-data/Aspose.Font/TTF/verdana.ttf
  • tests-data/Aspose.Font/Type1/courier.pfb
  • tests-data/Aspose.Font/CFF/29645.cff

Each test verifies that these specific fonts cannot be opened in evaluation mode and can be opened with the correct type and a nonzero glyph count after licensing. This does not imply that all fonts are restricted in evaluation mode.

The class runs sequentially. It clears the license before each test and restores the configured license afterward, including after failures. Do not run licensing tests concurrently with other font tests in the same JVM. The alwaysRun lifecycle hooks also execute when selecting the LicensingExamples group.

BaseTest writes its normal log under tests-out/Aspose.Font.Java; these examples do not save font files or print license contents.

Reusing the snippets

For the file and stream snippets, supply licenseFilePath as the full path to your license file. The stream snippet requires java.io.InputStream and java.io.FileInputStream imports and uses try-with-resources. Calling methods must handle or declare Exception. Test setup, font loading checks and assertions are outside the snippet markers.

Related Documentation

Related Resources

Requirements

  • JDK 8 or later and Maven for this test project
  • Aspose.Font for Java library
Aspose.Font for Java – Licensing Examples
// Clear the previously installed license and return to evaluation mode.
// Learn more: https://docs.aspose.com/font/java/licensing/
com.aspose.font.License license = new com.aspose.font.License();
license.setLicense("");
// Apply a license from a file.
// Learn more: https://docs.aspose.com/font/java/licensing/
// licenseFilePath is the full path to your Aspose.Font for Java license.
com.aspose.font.License license = new com.aspose.font.License();
license.setLicense(licenseFilePath);
// Apply a license from a stream and close the stream after use.
// Learn more: https://docs.aspose.com/font/java/licensing/
// licenseFilePath is the full path to your Aspose.Font for Java license.
com.aspose.font.License license = new com.aspose.font.License();
try (InputStream licenseStream = new FileInputStream(licenseFilePath)) {
license.setLicense(licenseStream);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment