How to get an image or shape location relative to the page on all wrapping style

Hello.


Can you help me? i need to get the image or shape location relative to the page no matter what the wrapping style is. 
I used to got it from its bounding box attribute. but in DocIO i cant find it, 

This is my code right now

private BookmarkLocation? GetPictureCoordinatesRelativeToPage(WDocument document, WPicture picture)
{
    // If it's inline (not a floating shape) we can't get page coordinates
    if (picture.TextWrappingStyle == TextWrappingStyle.Inline)
        return null;


    // Try to find the section that contains the shape's owner paragraph
    WParagraph ownerParagraph = picture.OwnerParagraph;
    WSection ownerSection = null;
    foreach (WSection sec in document.Sections)
    {
        foreach (var bodyItem in sec.Body.ChildEntities)
        {
            if (bodyItem == ownerParagraph)
            {
                ownerSection = sec;
                break;
            }
        }
        if (ownerSection != null)
            break;
    }


    // Fallback if not found: use first section
    if (ownerSection == null && document.Sections.Count > 0)
        ownerSection = document.Sections[0];


    // Page margins (points)
    double leftMargin = ownerSection?.PageSetup.Margins.Left ?? 0;
    double topMargin = ownerSection?.PageSetup.Margins.Top ?? 0;


    // Get base horizontal/vertical offsets from shape
    double x = picture.HorizontalPosition; // unit: points
    double y = picture.VerticalPosition; // unit: points
    double width = picture.Width;
    double height = picture.Height;


    // Adjust horizontal by origin
    switch (picture.HorizontalOrigin)
    {
        case HorizontalOrigin.Page:
            // x is already relative to page left
            break;
        case HorizontalOrigin.Margin:
            x += leftMargin;
            break;
        case HorizontalOrigin.Column:
            x += leftMargin; // approximate: columns are inside margins; for multi-column you may need column offset
            break;
        case HorizontalOrigin.Character:
            // character origin is relative to the paragraph run — exact coordinate requires layout
            break;
    }


    // Adjust vertical by origin
    switch (picture.VerticalOrigin)
    {
        case VerticalOrigin.Page:
            // y is already relative to page top
            break;
        case VerticalOrigin.Margin:
            y += topMargin;
            break;
        case VerticalOrigin.Paragraph:
        case VerticalOrigin.Line:
            // these require layout to convert to page coordinates
            break;
    }


    return new BookmarkLocation
    {
        LowerLeftX = PointsToPixels(x, 72),
        LowerLeftY = PointsToPixels(y + height, 72),
        UpperRightX = PointsToPixels(x + width, 72),
        UpperRightY = PointsToPixels(y, 72),
    };
}

i am able to get the location when the image is floating. but if the image is inline or inside a table. i cant get the real coordinate. 

i want to know if i can get what i need from SyncFusion before using it for production. 

Thank you so much


2 Replies

KP Kathiresan Paranthaman Syncfusion Team October 27, 2025 02:54 PM UTC

Hi Dimas,
We have reproduced the reported issue “Relative position of images and shapes not maintained properly in DocIO” in our end. We will validate this issue and update you with more details within 2 days.

Regards,
Kathiresan.



DS Dharanya Sakthivel Syncfusion Team October 29, 2025 07:52 PM UTC

Dimas,

Regarding: “If the image is inline, I can't get the real coordinate.”
From the details you shared, we understand that you want to get the position of an image when it is inline. In Microsoft Word, when an image or shape is inserted as inline, it behaves like a character in the text. In this mode, layout positioning is not available, so it’s not possible to set or get its exact position on the page. This is expected behavior.


Regarding: “If the image is inside a table, I can't get the real coordinate.”
When an image is placed inside a table, its horizontal position is calculated relative to the table cell or container position, not the page. This is standard behavior in Microsoft Word.

Regards,
Dharanya.


Loader.
Up arrow icon