Relfection error when calling Aspose from JS

After a new installtion of Apsose libraries (and sorry, have no idea what they do…) a previously working application now reports:
java.lang.reflect.Invocation.TargetException
I have not the foggiest what causes this. Are there any logs that Aspose keeps that canhelp me debugging this? The previous deployed application ran on an older version of Java, could that be a reason? Am I missing a library? A License? Any hint?

@petermariavh

Could you please provide more details about the specific Aspose libraries you installed and the version of Java you are currently using?

Apsose PDF and Aspose Cells. Running now on Java 22.

This is teh code:
var license = Java.type(“com.aspose.pdf.License”);
var doc = Java.type(“com.aspose.pdf.Document”);
var pageCol = Java.type(“com.aspose.pdf.PageCollection”);
var textStamp = Java.type(“com.aspose.pdf.TextStamp”);
var fontRepo = Java.type(“com.aspose.pdf.FontRepository”);
var txtState = Java.type(“com.aspose.pdf.TextState”);
var align = Java.type(“com.aspose.pdf.HorizontalAlignment”);
var title = Java.type(“com.aspose.pdf.HtmlFragment”);
var margin = Java.type(“com.aspose.pdf.MarginInfo”);
var floatBox = Java.type(“com.aspose.pdf.FloatingBox”);
var font = Java.type(“com.aspose.pdf.Font”);

var lic = new license();
lic.setLicense(“Aspose.PDF.Java.lic”);

var srcDir = getvar(‘sys.job-dir’) + ‘/output/’
var files = fs.listNames(srcDir)
var fileName = ‘’
for(var i=0; i<files.length; i++) {
if (files[i].match(/.pdf$/i)) {
fileName = files[i]
break
}
}
if (!fileName) {
job.fail('Generated Statement can not be located in ’ + srcDir)
}

if (fileName.match(/'/g) || fileName.match(/\ /g)) {
fs.copy(srcDir + fileName, srcDir + fileName.replace(/'/gi, ‘’).replace(/ /gi, ‘’))
console.log(“copied file”)
}
console.log(‘Found ’ + fileName)
fileName = fileName.replace(/’/gi, ‘’).replace(/ /gi, ‘’);

var mainArrayPages = new doc(srcDir + fileName).getPages();
var mainDoc = new doc();
mainDoc.getPages().add(mainArrayPages);
var totalPages = mainDoc.getPages().size();
AddPageNoTextStamp(mainDoc.getPages());

mainDoc.save(getvar(“sys.job-dir”) + “/output/” + “PN” + totalPages + “" + fileName);
setvar(‘BaseDocumentName’, “PN” + totalPages + "
” + fileName)

function AddPageNoTextStamp(pageColl) {
var state = new txtState();
state.setFontSize(7);
var f = fontRepo.openFont(“/usr/share/fonts/CenturyGothic.ttf”);
state.setFont(f);

var txtStamp = new textStamp("", state);
txtStamp.setHorizontalAlignment(align.Right);
txtStamp.setRightMargin(50);
txtStamp.setYIndent(35);

var totalPages = pageColl.size();
for (var i=5; i <= totalPages; i++) {
    var page = pageColl.get_Item(i);
    txtStamp.setValue(i-4);
    **page.addStamp(txtStamp);**

and thsi is the error:
Original error message: java.lang.reflect.InvocationTargetException
at ‘AddPageNoTextStamp’ (line: 60)
at ‘print via sftp’ (line: 40)
I marked the line where it fails with *****

Sorry, made a msitake abot the java version, it is: java.runtime.version - 17.0.14+7-LTS
And these are the aspose file we load:
total 116540
4 -rw-r–r–. 1 inspire quadient 1209 Mar 13 06:44 Aspose.Cells.Java.lic
4 -rwxr-xr-x. 1 inspire quadient 1043 Mar 13 06:44 Aspose.PDF.Java.lic
480 -rw-r–r–. 1 inspire quadient 488652 Mar 13 06:44 aspose-cells-23.8-gridweb-javadoc.jar
116 -rw-r–r–. 1 inspire quadient 115668 Mar 13 06:44 aspose-cells-23.8-gridweb-resources.jar
7952 -rw-r–r–. 1 inspire quadient 8141053 Mar 13 06:44 aspose-cells-23.8-gridweb.jar
2796 -rw-r–r–. 1 inspire quadient 2860190 Mar 13 06:44 aspose-cells-23.8-javadoc.jar
8404 -rw-r–r–. 1 inspire quadient 8603923 Mar 13 06:44 aspose-cells-23.8.jar
4 -rw-r–r–. 1 inspire quadient 388 Mar 13 06:44 aspose-cells-23.8.pom
71968 -rwxr-xr-x. 1 inspire quadient 73692790 Mar 13 06:44 aspose-pdf-21.2.jar

@petermariavh

Have you renewed your license as well? What was the previous Aspose.PDF version you were using which was running without any issues? Please try using 25.2 version of the API and let us know if issue still persists.

Hi Asad,
as said, I have no idea how Apsose works. ‘Someone’ copied the files over to the new environment. I’m not even sure about the version, but I suppose it is 21. for PDF and 23.8 for celss, as indicated by the filenames. The license, is there a way to check it? Do I need a new one for a new server or a new version? And last but not least, can I download the new versions from the Aspose sit4 directly? Sorry for so many questions, this is a very dark box to me…

@petermariavh

Please make sure that correct JAR of Aspose.PDF for Java is placed/copied in new environment. In your case, the JAR should be JDK17 targeted which can surely be downloaded from Aspose site directly. For example at below link: (you can download the version as per your license support)

It depends upon the type of your subscription. If your existing subscription allows you multiple distribution, you can keep using same license on different environment. You can check license types at below link:

Please also note that we always recommend using the latest version of the API and at the moment it is 25.2. We suggest that you try using this version and let us know if issue still occurs. Please share sample PDF document along with some steps to reproduce the issue in our environment so that we can test it and address it accordingly.

Thanks, Asad, that helps.
I’ll let you know how it goes.
pm

Well, the customer never updated the license file, so they have another issue now. I let them sort that out and then look further.

@petermariavh

Please take your time to investigate the possible reasons and feel free to reach out when you have some information to share.

Hi Asad,
Just to give you an update, I downloaded the jars, that was no problem, but then we found out the client never updated the license file and they don’t even know how to get it. :frowning:
I’m waiting for them to sort it out. Is there mybe a test licenses or such so I could go ahead with my part of the work?
Thanks

@petermariavh

If your application was running fine before update and you do not want to upgrade its version or you did not upgrade it, you do not need to update the license. You just need to make sure that your license is properly placed and set in the code:

In case you want to test with the latest version of the API and your current license do not support it, you can download and obtain a free 30-days temporary license to evaluate the latest version of the API. Your existing license will remain valid for the API versions that were released before its date of expiry. You can open the license file in notepad or any text editor to check its SubscriptionExpiry.