Determine Coordinates of StraightConnector1 Shapes in Word DOCX Document using C# or Java | Unable to Detect Objects Visually

Good day!
We solve the problem of finding shape objects on the page (for example, STRAIGHT_CONNECTOR_1)
We ran into a problem when a certain number (24) of other objects (SHAPE like STRAIGHT_CONNECTOR_1) are found in a paragraph. But we do not see such objects visually in the document.
Please tell me how:

  1. Either select the corresponding STRAIGHT_CONNECTOR_1 objects visually in the document (paint, frame, etc.)
  2. Or make an exception for such cases, when the object is not visually visible and cannot be detected in any way, and skip these elements when checking the document.
    The document is attached: test.zip (30.0 KB)

The code is attached: ParagraphWithStraightConnectors.zip (753 Bytes)

@beralex,

You can visualize these StraightConnector1 type Shapes by using OpenOffice Writer desktop application (see screenshot.png (36.1 KB)). These are even visible in MS Word 2019; just scroll down to the bottom of first page.

Aspose.Words can also recognize these Shapes. But, can you please elaborate your inquiry further by providing complete details of your usecase? Do you want code to delete those Shapes of type “StraightConnector1”? Or what exactly your requirement is? This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

@awais.hafeez,
Yes, I attached a not entirely visual document. I am enclosing a document composed as follows (see Files.zip (230.7 KB)):

  1. At the end of the page, a paragraph (highlighted in yellow in the document) that has a connection with shape elements of type STRAIGTH_CONNECTOR_1 (see Demo_doc_shape_straight_connector.docx.)
  2. Note that the line at the end of the page is not visible (see Screen1.png).
  3. After shifting this paragraph to the beginning of the next page, a line appears (see Screen2.png).

Question:

  • How can I highlight this line without a paragraph shift?
  • Or how can I tell to the user if the line is outside the visible area? We need to distinguish this line from the line that is visible on the page without additional manipulation of the document.

@beralex,

Please try the following C# codes:

// Code to get the anchor Paragraphs of StraightConnector1 Shapes
Document doc = new Document("C:\\temp\\Files\\Demo_doc_shape_straight_connector.docx");

ArrayList list = new ArrayList();
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
    if (shape.ShapeType == ShapeType.StraightConnector1)
    {
        Paragraph para = (Paragraph)shape.GetAncestor(NodeType.Paragraph);
        if (para != null && !list.Contains(para))
            list.Add(para);
    }
}

foreach (Paragraph paragraph in list)
    // for example change highlight color of text
    foreach (Run run in paragraph.Runs)
        run.Font.HighlightColor = Color.Red;

doc.Save("C:\\temp\\Files\\20.9.docx");

// Code to determine the coordinates of StraightConnector1 Shapes
Document doc = new Document("C:\\temp\\Files\\Demo_doc_shape_straight_connector.docx");

LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

Console.WriteLine("72 points equal 1 inch");
Console.WriteLine("----------------------");
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
    if (shape.ShapeType == ShapeType.StraightConnector1)
    {
        layoutEnumerator.Current = layoutCollector.GetEntity(shape);

        Console.WriteLine("Start: (" + layoutEnumerator.Rectangle.Left + ", " + layoutEnumerator.Rectangle.Top + ") " +
"End: (" + (layoutEnumerator.Rectangle.Left + layoutEnumerator.Rectangle.Width) + ", " + (layoutEnumerator.Rectangle.Top + layoutEnumerator.Rectangle.Height) + ") ");
    }
}

Thanks. These methods helped.