Hello,
I am using Aspose.Words 21.2 to replace Charts/SmartArt with images in a document. When running on the attached doc with a chart object, the right and bottom borders no longer appear after replacement. I am using .NET Framework 4.7.2. Sample code is below. I noticed that when using .NET Core 3.1, the borders don’t disappear, so there seems to be some issue with Aspose.Words and the .NET Framework at play here.
chart_convertedImages_borderIssue.zip (33.5 KB)
public static int ExtractShapesAsposeWords(string filePath, string fileName)
{
Document doc = new Document(filePath);
List<Shape> shapes = doc.GetChildNodes(NodeType.Shape, true).Cast<Shape>().ToList();
Dictionary<string, Shape> shapesToReplace = new Dictionary<string, Shape>();
int numShapes = 0;
foreach (Shape shape in shapes)
{
if (!(shape.HasChart || shape.HasSmartArt)) continue;
DocumentBuilder builder = new DocumentBuilder(doc);
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
options.UseHighQualityRendering = true;
options.UseAntiAliasing = true;
using (MemoryStream stream = new MemoryStream())
{
shape.GetShapeRenderer().Save(stream, options);
builder.MoveTo(shape);
InsertImageIntoDoc(builder, stream, shape);
shape.Remove();
}
numShapes++;
}
if (!string.IsNullOrEmpty(ExtractDir) && numShapes > 0)
{
Console.WriteLine(fileName + "- DONE Aspose Extraction. " + numShapes + " artifacts were replaced.");
doc.Save( filePath);
}
return numShapes;
}
private static Shape InsertImageIntoDoc(DocumentBuilder builder, Stream imgContent, Shape sourceShape)
{
Shape shapeWithImage = null;
if (sourceShape.IsInline)
{
shapeWithImage = builder.InsertImage(imgContent, sourceShape.Width, sourceShape.Height);
}
else
{
shapeWithImage = builder.InsertImage(imgContent, sourceShape.RelativeHorizontalPosition, sourceShape.Left,
sourceShape.RelativeVerticalPosition, sourceShape.Top, sourceShape.Width, sourceShape.Height,
sourceShape.WrapType);
}
return shapeWithImage;
}