Inserted image - no borders or shadow

This code use to work in a previous version of Aspose.Words. It would insert an image, set a black border, and a shadow effect.


builder.MoveToDocumentEnd();
Aspose.Words.Drawing.Shape shape = builder.InsertImage(thumbnail);
double ratio = shape.Height / shape.Width;
shape.Width = ConvertUtil.InchToPoint(7.0);
shape.Height = shape.Width * ratio; // Maintain aspect ratio
shape.ImageData.Borders.Color = Color.Black;
shape.ImageData.Borders.Shadow = true;
shape.ImageData.Borders.LineStyle = Aspose.Words.LineStyle.Single;
shape.ImageData.Borders.LineWidth = 1;
builder.MoveToDocumentEnd();

In version 16.1 I get the image, and kind of a border, and no shadow.

What am I missing?
Hi Richard,

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

  • Your input Word document
  • Aspose.Words 16.1.0 generated output document showing the undesired behavior
  • Your expected document (generated by some old version of Aspose.Words) which shows the correct output.
  • Please provide information about the Aspose.Words' version number for which there were no problems on your side previously
  • The image file

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

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

Best regards,

Sorry for the long delay. I ended up retro-grading to meet a deadline. Now I’m back trying to fix this problem - this time using the latest Aspose.Words 16.5.0.0


Super simple sample code with no input document …

static void Main(string[] args)
{
Document docNew = new Document();
DocumentBuilder builder = new DocumentBuilder(docNew);

Shape shape = builder.InsertImage(@“C:\test\image.png”);

shape.ImageData.Borders.Color = Color.Black;
shape.ImageData.Borders.LineStyle = LineStyle.Single;
shape.ImageData.Borders.LineWidth = 1;
shape.ImageData.Borders.Shadow = true;

docNew.Save(@“C:\test\output.docx”);

// Open output.docx and no borders!
}
Hi Richard,

Thanks for your inquiry. I am afraid, both Aspose.Words for .NET 16.5.0 and 16.1.0 versions produced similar outputs on our end. Could you please also provide a little more information about the Aspose.Words' version number for which there were no problems on your side previously?

Best regards,

Did those outputs have a border?


I had to go back to version 11.7 (2012.08.31) to make it work, but I couldn’t tell you exactly what version is started failing. Version 11.7 falls over when trying to work with Word 2016 documents however, so I’m kind of stuck. :frowning:

Hi Richard,


Thanks for your inquiry. Using the code from your post, I have generated some documents using different versions of Aspose.Words and attached them here for your reference. There is some difference between 11.7.0 and 16.6.0 outputs. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-13890. Your thread 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 Richard,


After further investigation on WORDSNET-13890, our product team has come to a conclusion that this issue and the undesired behavior you’re observing is actually not a bug in Aspose.Words. So, they will close this issue as ‘Not a Bug’. Please see following details:

In the old versions of Aspose.Words the DocumentBuilder.InsertImage method inserted images as a VML shape. Now images are inserted as DrawingML. It was done on implementing WORDSNET-10837 in the version 15.2.

We can suggest to you to create a document optimized for the older version of MS Word:

<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>Document docNew = new Document();
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>docNew.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>DocumentBuilder builder = new DocumentBuilder(docNew);

or create a shape manually:

<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>Document docNew = new Document();
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>DocumentBuilder builder = new DocumentBuilder(docNew);
 
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>Shape shape = new Shape(docNew, ShapeType.Image);
 
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.ImageData.ImageBytes = File.ReadAllBytes(myDir + @“image.png”);
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Default;
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.Left = 0;
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.RelativeVerticalPosition = RelativeVerticalPosition.TextFrameDefault;
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.Top = 0;
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.WrapType = WrapType.Inline;
 
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>builder.InsertNode(shape);
 
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.ImageData.Borders.Color = Color.Black;
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.ImageData.Borders.LineStyle = LineStyle.Single;
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.ImageData.Borders.LineWidth = 1;
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>shape.ImageData.Borders.Shadow = true;
 
<span style=“font-family: Consolas, “Bitstream Vera Sans Mono”, “Courier New”, Courier, monospace !important;”>docNew.Save(myDir + @“Out.docx”);

Best regards,