Can not set ImageData attributes

Hello,

I am trying to set some ImageData attributes such as bottom border or bottom crop but it does not seems to works since Aspose Words 15.2.0 (merge Shape / DrawingML). I want to migrate to Aspose Words 16.11.0

I do the following code,

Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
InputStream image = new FileInputStream(new File(“C:\test.png”));
Shape shape = builder.insertImage(image);
ImageData imageData = shape.getImageData();
Border bottomBorder = imageData.getBorders().getByBorderType(BorderType.BOTTOM);
bottomBorder.setLineStyle(LineStyle.SINGLE);
bottomBorder.setLineWidth(1);
bottomBorder.setColor(Color.BLACK);
bottomBorder.setShadow(true);
document.save(“test.docx”);

The document test.docx does not have bottom border for Aspose version 16.11.0 but the same code works in Aspose version < 15.2.0

Thank you in advance for your assistance.

Jean Pascal Lim

Hi Jean,


Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 16.11.0, we managed to reproduce this issue on our end. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-14520. Your request has also been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Hi Jean,


Regarding WORDSNET-14520, our product team has completed the work on your issue and has come to a conclusion that this is not a bug in Aspose.Words. Your issue (WORDSNET-14520) will be closed with ‘Not a Bug’ resolution.

It is expected behavior. The problem occurs because the inserted shape was inserted as DrawingML.

Starting from Aspose.Words 15.2.0 all Shapes are inserted to the document as DrawingML shapes (upon using DocumentBuilder). DrawingML shapes do not implement borders and can have only outlines (according to spec ISO-IEC_29500).

The simple way to get expected result is to set an earlier version of MS Word (for example MsWordVersion.Word2007). In this case the particular shape will be inserted as VML shape. Please see the following code:

<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>document.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2007);

Also you can try to create needed Shape manually to get expected result:

<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);

// This constructor creates shape with markup language “Vml”.
Shape shape = new Shape(document, ShapeType.IMAGE);
// Set path to file here.
InputStream is = new FileInputStream(new File(“D:\temp\aspose.words.jpg”));

ByteArrayOutputStream buffer = new ByteArrayOutputStream();

int nRead;
byte[] data = new byte[16384];

while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}

buffer.flush();

shape.getImageData().setImageBytes(buffer.toByteArray());
shape.setWrapType(WrapType.INLINE);

ImageData imageData = shape.getImageData();
Border bottomBorder = imageData.getBorders().getByBorderType(BorderType.BOTTOM);
bottomBorder.setLineStyle(LineStyle.SINGLE);
bottomBorder.setLineWidth(1);
bottomBorder.setColor(Color.BLACK);
bottomBorder.setShadow(true);

builder.insertNode(shape);

document.save(“D:\temp\awjava-17.1.0.docx”);

Best regards,