Remove Figure Border
@Shreedhar21 Unfortunately, your requirements are not quite clear. Could you please attach your sample input and expected output documents? We will check them and provide you more information.
@Syedfahad @Shreedhar21 Could you please attach your sample input and expected output documents? We will check them and provide you more information.
@Syedfahad To remove shape borders you could set the Shape.Stroked
property to false. To remove the borders for all shapes in the document you could use the following code:
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
shape.Stroked = false;
@Syedfahad Generally you can use code like this to remove border of the shapes in your document:
Document doc = new Document(@"C:\Temp\in.docx");
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
// Remove border of images.
foreach (Shape s in shapes)
{
s.Stroke.On = false;
}
doc.Save(@"C:\Temp\out.docx");
If you nee to remove border only of image shapes that are alone on the page, you can use code like this:
Document doc = new Document(@"C:\Temp\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
List<Shape> shapes = doc.GetChildNodes(NodeType.Shape, true)
.Cast<Shape>().Where(s => s.HasImage && s.IsTopLevel).ToList();
// Remove border of image if it is alone on the page.
// First group shapes by pages,
Dictionary<int, List<Shape>> shapesByPage = new Dictionary<int, List<Shape>>();
foreach (Shape s in shapes)
{
int page = collector.GetStartPageIndex(s);
if (!shapesByPage.ContainsKey(page))
shapesByPage.Add(page, new List<Shape>());
shapesByPage[page].Add(s);
}
// Now we can remove border if there is only one shape on the page.
foreach (int p in shapesByPage.Keys)
{
if (shapesByPage[p].Count == 1)
shapesByPage[p][0].Stroke.On = false;
}
doc.Save(@"C:\Temp\out.docx");