Add Text to XPS document using Aspose.Page - Index out of range Exception Occurs

XpsGlyphs glyphs = xps.insertGlyphs(0, font, fontsize, XpsFontStyle.Regular, x, y, context);
Exception in thread “main” class com.aspose.page.internal.l16l.I114: Index out of range: 0.
com.aspose.xps.XpsElement.lif(Unknown Source)
com.aspose.xps.XpsDocument.lif(Unknown Source)
com.aspose.xps.XpsDocument.insert(Unknown Source)
com.aspose.xps.XpsDocument.insertGlyphs(Unknown Source)

file:file.zip (54.9 KB)

using insertGlyphs() failed,but addGlyphs() Successful,why?
This I need to call insertGlyphs().

@yufeic

Would you please also share the complete code snippet that you are trying at your side. We will test the scenario in our environment and address it accordingly.

@asad.ali

code:
public static void main(String[] args) throws FileNotFoundException {
String inputFile=“C:\Users\Administrator\Desktop\2.xps”;
String outputFile=“C:\Users\Administrator\Desktop\11.xps”;
String license = “E:\Aspose.XPS.lic”;

if (!getLicense(license)) {
System.out.println(“license error!”);
return ;
}

XpsDocument xps = new XpsDocument(inputFile);
int page = xps.getPageCount();
float width = xps.getPage().getWidth();
float height = xps.getPage().getHeight();

for (int i=1; i<page+1; i++){
xps.selectActivePage(i);
XpsBrush color = xps.createSolidColorBrush(Color.black);
XpsGlyphs glyphs = xps.insertGlyphs(0, “Arial”, 24, XpsFontStyle.Regular, 300f, 450f, “Hello World!”);
//XpsGlyphs glyphs = xps.insertGlyphs(1, “Arial”, 24, XpsFontStyle.Regular, 300f, 450f, “Hello World!”);
XpsMatrix XM = xps.createMatrix(1, 0, 0, 1, 0, 0);
XM.rotateAround(0, new Point2D.Float(width/2, height/2));
glyphs.setRenderTransform(XM);
glyphs.setFill(color);
}
xps.save(outputFile);
System.out.println(“ok!”);
}

file:2.zip (54.9 KB)

@yufeic

We have logged an issue as PAGEJAVA-71 in our issue tracking system for the sake for further investigation. We will look into details of this scenario and keep you posted with the status of ticket resolution. Please spare us little time.

We are sorry for the inconvenience.

@asad.ali
How is the problem solved?

@yufeic

As the issue has been logged in our issue tracking system, we will further investigate the reasons behind this. As soon as the issue is resolved, we will inform you within this forum thread. Please be patient and spare us little time.

@yufeic

We would like to share with you that your issue has been resolved. Please download and use Aspose.Page for Java 19.12 and in case you face any other issue, please let us know.