0

I have a spring-boot application which has a public rest api endpoint. The api extracts text from a given pdf file. I am loading the Aspose license in a static initialising block and it loads correctly.

public class AsposeLicenseLoader {

  private static Logger logger = LoggerFactory.getLogger(AsposeLicenseLoader.class);

  private static boolean isLicenseLoaded;


  public static void doLoad(AsposeConfig asposeConfig) {

    String location = asposeConfig.license().location();
    logger.debug("Loading Aspose license \"{}\"", location);
    try (InputStream is = AsposeLicenseLoader.class.getClassLoader()
        .getResourceAsStream(location)) {
      com.aspose.pdf.License pdfLicense = new com.aspose.pdf.License();
      pdfLicense.setLicense(is);
      isLicenseLoaded = true;
      logger.info("Aspose  license loading completed");
    } catch (Exception e) {
      logger.error("Unable to load the Aspose  license", e);
    }
  }


  public static boolean isAsposeLicenseLoaded() {
    return isLicenseLoaded;
  }

When I try to extract text from pdf the output shows the license is not applied correctly with the following output.

Evaluation Only. Created with Aspose.Pdf. Copyright 2002-2017 Aspose Pty Ltd.

The the text extraction logic in my application below.

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(filePath);

    // Create TextAbsorber object to extract text
    com.aspose.pdf.TextAbsorber textAbsorber = new com.aspose.pdf.TextAbsorber();

    // Accept the absorber for all the pages
    pdfDocument.getPages().accept(textAbsorber);

    // Get the extracted text
    extractedText = textAbsorber.getText();

However if I explicitly load the license just before the text is extracted then it applies the license correctly and extracts the full text from the file. As per the documentation of aspose I only need to load the license once and not for each incoming request. Does anyone know if I am missing anything here?

I have looked at the official aspose documentation and followed their instructions. Also looked at similar issues posted by other members. https://forum.aspose.com/t/loading-aspose-license-in-aspose-java/62945/2

  • Please note that Aspose.PDF dedicated support forum is the right place to post such issues as this is where you can track its progress and receive appropriate updates. Please create an inquiry or topic there and we will further proceed to assist you accordingly. This is Asad Ali and I work as Developer Evangelist at Aspose. – Asad Ali Feb 06 '23 at 19:09
  • Upgrading it to 23.1 version of the library worked. – user18905365 Feb 07 '23 at 13:41

0 Answers0