Image Not Dispalying Correctly in Word

I am having a difficult time displaying an image using the Image mailmerge tag. I use this tag

<<Image(100pt;100pt):StateCube1>>

When I put this image tag inside a word text box - once rendered the image comes across great except it does not fill the text box. In the rendered doc - If I resize the text box just a tad - then the image fills in - so the image data is there it just doesn’t display correctly.

The same thing happens if I just use the Image tag by itself - not in a word text box.

Any ideas as to how i can get this image to display correctly with the dimensions that I specify?

@john.nelson

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

asposeTest.zip (135.0 KB)

I do not have the time to create a standalone app. But here are the files i refer to. It’s pretty straight forward. I create the same images for powerpoint and the sizes are fine. I think it’s a word thing. wondering of ou have seen this before.

Is this an option?

Using the size parameters? I cannot get this to work though.

<<Image(100pt;100pt):mlStateCube1>>

I am using this version…

aspose-words-19.4-jdk17.jar

@john.nelson

Please ZIP and attach the images that you are inserting into document. We will write the code example for mail merge and test this case. Thanks for your cooperation.

The images are created on the fly using the technique you recommend - using the callback method like so. If you want a copy of an example image that is created - they are in the documents I provided in the last zip.

Here is a source code snippet

public static class HandleMergeImageFieldFromBlob implements IFieldMergingCallback {

  private DocumentBuilder mBuilder;

   public void fieldMerging(FieldMergingArgs e) throws Exception {

   }


   /*
    * This is called when mail merge engine encounters Image:XXX merge field in the document.
    * You have a chance to return an Image object, file name or a stream that contains the image.
    */

   public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
       // The field value is a byte array, just cast it and create a stream on it.

       if ((e.getFieldName().startsWith("riskCubeImage")
             
               || (e.getFieldName().startsWith("mlIssueCubeImage"))


       ))
       {



           ByteArrayOutputStream baos = (ByteArrayOutputStream)e.getFieldValue();
           ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) baos.toByteArray());
           e.setImageStream(imageStream);

       /* this is from aspose to fix this casting error in their version5 jar file
       // it didn't work

       ByteArrayOutputStream os = new ByteArrayOutputStream();
       ImageIO.write((BufferedImage) e.getFieldValue(), "jpg", os);
       InputStream is = new ByteArrayInputStream(os.toByteArray());
       e.setImageStream(is);
       */
        }
   }

}

@john.nelson

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-21405. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier have been fixed in this Aspose.Words for .NET 20.12 update and this Aspose.Words for Java 20.12 update.

Thank you - how can I get the version that is not evaluation?

@john.nelson

If you already have Aspose.Words’ license, please open it in notepad. You will see the following tag in your license file:

<SubscriptionExpiry>20210925</SubscriptionExpiry>

It means that you can free upgrade to a version of Aspose.Words that is published before 09/25/2021.

If you do not have license or your license does not allow you to upgrade, please contact our sales team.