TextLayer getText() method doesn't work

I am reading a pub file and at some point after casting a Layer to TextLayer I call the getText() method.
Sometimes this returns the name of the layer. Sometimes that print doesn’t appear to be executed at all. I was expecting it to return a String for the full text of the layer but it doesn’t.
Also the code you see commented out was throwing exceptions:

class com.aspose.psd.internal.jx.q (in unnamed module @0x1d269ed7) cannot access class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl (in module java.base) because module java.base does not export sun.reflect.generics.reflectiveObjects to unnamed module @0x1d269ed7
at com.aspose.psd.internal.jx.q.a(Unknown Source)
at com.aspose.psd.internal.jx.q.a(Unknown Source)
at com.aspose.psd.fileformats.psd.layers.layerresources.Txt2Resource.e(Unknown Source)
at com.aspose.psd.internal.iY.au.a(Unknown Source)
at com.aspose.psd.internal.iY.au.getFont(Unknown Source)
at com.aspose.psd.fileformats.psd.layers.TextLayer.getFont(Unknown Source)
at Main.main(Main.java:81)
Here is the code fragment

if (layer instanceof TextLayer) {
TextLayer textLayer = (TextLayer) layer;
float textBoxHeight = textLayer.getTextBoundBox().getHeight();
float textBoxWidth = textLayer.getTextBoundBox().getHeight();
int textBoxTop = textLayer.getTop();
;
int textBoxLeft = textLayer.getLeft();
String text = textLayer.getText();
System.out.println(“text:” + text);
System.out.println("textBoxHeight " + textBoxHeight);
System.out.println("textBoxWidth " + textBoxWidth);
System.out.println("textBoxTop " + textBoxTop);
System.out.println("textBoxLeft " + textBoxLeft);
String innerText = textLayer.getInnerText();
System.out.println(“innerText:” + innerText);
for (TextFontInfo font : textLayer.getFonts()) {
System.out.println("font: " + font.getFamilyName());
}
// System.out.println(“textLayer.getFont():”+textLayer.getFont()); throws exception
// System.out.println(“textLayer.getTextColor():”+textLayer.getTextColor()); throws exception
// System.out.println(“textLayer.getTextData():”+textLayer.getTextData());

@elickerman please try the following additional command line parameters for javac:

–add-opens=java.base/java.util.regex=ALL-UNNAMED
–add-opens=java.base/sun.reflect.generics.reflectiveObjects=ALL-UNNAMED

Sometimes commands can differ.

That didn’t work but what I discovered was that java 17 made the module class path reflection restrictions strictly enforced. So I went back to java 8 and now this works.

The problem is that none of the text methods getText(), getInnerText() or getTextData() return the full text of a text layer. It’s always just the first few words, essentially what the layer was named. When I export using Photoshop scripting I see the full text. I can use a hybrid approach to solve my problem, half Aspose/have photoshop script, but it would be faster if Aspose could access the full text of textlayers

@elickerman
Please check the following article:

For the complex text layers is better to use ITextPortion API that supports different styles in one Text.

        TextLayer textLayer = (TextLayer) image.getLayers()[1];
        IText textData = textLayer.getTextData();
        string text = textData.getText();

If it doesn’t work for you input file, please attach input file to this forum topic for the investigation.