Image is rendered over the table after mail merge using Java

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

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

@cebiv

Please use Shape.WrapType as Inline to get the desired output. Hope this helps you.

@tahir.manzoor: Thanks

it is working after I change shape.wrapType = WrapType.INLINE.

@cebiv

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.