Add image to XPS document using Aspose.Page for Java - content will be left blank

@wanyangye

We will surely consider your concerns during investigation and will let you know as soon as some updates are available.

what’s new in page 19.9.

@wanyangye

Some bug fixes have been included in the latest release of the API. For further details, you can please check the release notes section in API documentation.

OCR-795: Is it solved?

@wanyangye

We regret to share that the issue is not yet resolved. We will surely let you know as soon as it is investigated and resolved. Please spare us little time.

We are sorry for the inconvenience.

e0ff4fcd-ba39-4544-a98e-07478ec65391.zip (59.7 KB)
I encountered a problem(page api):
Exception in thread “main” class com.aspose.page.internal.l16l.I114: Index out of range: 0.

@wanyangye

Are you converting these files into PDF? Would you please confirm so that we can test the scenario accordingly.

add watermark

@wanyangye

We are looking into it and will get back to you shortly.

Reproduce the fault?

@wanyangye

We have tested the scenario with Aspose.Page for Java 19.9 and following code snippet. We were unable to reproduce the issue. The output was created without any exception.

com.aspose.xps.XpsDocument doc = new com.aspose.xps.XpsDocument(dataDir + "e0ff4fcd-ba39-4544-a98e-07478ec65391.xps");
com.aspose.xps.XpsPath path = doc.addPath(doc.createPathGeometry("M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));
// Creating a matrix is optional, it can be used for proper positioning
path.setRenderTransform(doc.createMatrix(0.7f, 0f, 0f, 0.7f, 0f, 20f));
// Create Image Brush
path.setFill(doc.createImageBrush(dataDir + "avatar.png", new java.awt.geom.Rectangle2D.Double(0f, 0f, 258.24f, 56.64f), new java.awt.geom.Rectangle2D.Double(50f, 20f, 193.68f, 42.48f)));
// Save resultant XPS document
doc.save(dataDir + "AddImage_out.xps");

outputxps.zip (150.9 KB)

Would you please share the code snippet that you are trying at your end and facing the issue. We will again test the scenario in our environment and address it accordingly.

protected void addImage(int pageNum) {
xpsDoc.selectActivePage(pageNum);

    // Add Image
    String pathStr = String.format("M %s,%s L %s,%s %s,%s %s,%s Z",
            watermark.getX(),watermark.getY(),
            watermark.getX()+watermark.getW(),watermark.getY(),
            watermark.getX()+watermark.getW(),watermark.getY()+watermark.getH(),
            watermark.getX(),watermark.getY()+watermark.getH());
    XpsPath path = xpsDoc.addPath(xpsDoc.createPathGeometry(pathStr));
    // Creating a matrix is optional, it can be used for proper positioning
    path.setRenderTransform(xpsDoc.createMatrix(0.7f, 0f, 0f, 0.7f, 0f, 20f));
    // Create Image Brush
    path.setFill(xpsDoc.createImageBrush(watermark.getImgFilePath(),
            new Rectangle2D.Double(0, 0, watermark.getW(), watermark.getH()),
            new Rectangle2D.Double(watermark.getX(), watermark.getY(),
                    watermark.getX()+watermark.getW(), watermark.getY()+watermark.getH())));
    path.setOpacity(watermark.getTransparency());
}

My file is 4 pages, the first page has content, the second, third, and fourth pages are blank pages, and the blank page portion is not added to the watermark content.

@wanyangye

Could you please share the complete code snippet that you are using to add watermark.

In above piece of code, some values are unknown. Also, please share the code snippet of original method where addImage(int pageNum) is being called.

protected void addImage(int pageNum) {
xpsDoc.selectActivePage(pageNum);
// Add Image
String pathStr = String.format(“M %s,%s L %s,%s %s,%s %s,%s Z”,
watermark.getX(),watermark.getY(),
watermark.getX()+watermark.getW(),watermark.getY(),
watermark.getX()+watermark.getW(),watermark.getY()+watermark.getH(),
watermark.getX(),watermark.getY()+watermark.getH());
XpsPath path = xpsDoc.addPath(xpsDoc.createPathGeometry(pathStr));
// Creating a matrix is optional, it can be used for proper positioning
path.setRenderTransform(xpsDoc.createMatrix(0.7f, 0f, 0f, 0.7f, 0f, 20f));
// Create Image Brush
path.setFill(xpsDoc.createImageBrush(watermark.getImgFilePath(),
new Rectangle2D.Double(0, 0, watermark.getW(), watermark.getH()),
new Rectangle2D.Double(watermark.getX(), watermark.getY(),
watermark.getX()+watermark.getW(), watermark.getY()+watermark.getH())));
path.setOpacity(watermark.getTransparency());
}

OCR-795: When is it solved?

@wanyangye

Thank you for sharing requested code. We are checking it and will update you soon. About resolution of OCR-795, it has not been resolved yet. We have recorded your concerns and will let you know as soon as any update will be available.

It has been a long time, and it can be expedited.

New watermark:After adding a watermark, the resulting XPS file cannot be opened.AddImage_out.zip (403.9 KB)

@wanyangye

The issue has been successfully reproduced in our environment with Aspose.Page for Java 19.9 and logged under the ticket ID PAGEJAVA-61 in our issue tracking system. We will further look into this and keep you posted with the status of its correction. Please spare us little time.

As shared earlier, we have have recorded your concerns and will definitely take care of them during issue investigation.

Please note that the code snippet is still unable to execute due to above missing values. The object watermark.getY() is still missing with its definition. It was earlier requested that please share the code snippet of original method where addImage(int pageNum) is being called. It would help us testing the scenario in our environment accordingly.