Aspose: Image overflow the table when using with shape in imageFieldMerging

584 Views Asked by At

When I try to insert image directly to the ImageFieldMergingArgs it appears properly in the table cell using the following code...

override fun imageFieldMerging(imageFieldMergingArgs: ImageFieldMergingArgs) {
        val fieldValue = imageFieldMergingArgs.fieldValue
        if (fieldValue is DataString) {
            val decodedImage = fieldValue.decode()
            imageFieldMergingArgs.imageStream = ByteArrayInputStream(decodedImage)
        }
    }

But when I'm trying to insert an image using Shape in MailMerge. then it is appearing outside the table. I'm using the following code

override fun imageFieldMerging(imageFieldMergingArgs: ImageFieldMergingArgs) {
        val fieldValue = imageFieldMergingArgs.fieldValue
        if (fieldValue is DataString) {
            val shape = Shape(imageFieldMergingArgs.document, ShapeType.IMAGE)
            shape.wrapType = WrapType.SQUARE
            shape.aspectRatioLocked = false
            shape.anchorLocked = true
            shape.allowOverlap = false
            shape.width = imageFieldMergingArgs.imageWidth.value
            shape.height = imageFieldMergingArgs.imageHeight.value
            imageFieldMergingArgs.shape = shape
        }
    }

is there any way I can add an image into the table cell using shape to imageFieldMergingArgs.

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

When you specify imageFieldMergingArgs.imageStream the shape is inserted with WrapType.INLINE. In you second snippet you specify WrapType.SQUARE. This might be the difference. It is difficult to say exactly what is wrong without your template. But I would try specifying WrapType.INLINE. I tested both your code snippets on my side with a simple template an in both cases the image is inside table cell.