none
Get the location of an anchor element RRS feed

  • Question

  • I have a word document with an image positioned as follows: 

    <w:drawing>
              <wp:anchor distT="0" distB="0" distL="0" distR="0" simplePos="0" relativeHeight="251661312" behindDoc="0" locked="0" layoutInCell="0" allowOverlap="1" wp14:anchorId="02DF6AED" wp14:editId="5015B7C6">
                <wp:simplePos x="0" y="0"/>
                <wp:positionH relativeFrom="character">
                  <wp:posOffset>986155</wp:posOffset>
                </wp:positionH>
                <wp:positionV relativeFrom="line">
                  <wp:posOffset>-346075</wp:posOffset>
                </wp:positionV>...

    What I would like to do is figure out what these offsets are in terms of the page. So perhaps the offset of the line from the page and the offset of the character from the page? Is this possible? How is Word remembering where to draw the anchor? Is there a parent line or character element somewhere?

    For a little context I am inserting this xml into the document with the office.js api at the location of the cursor in the document, then I end up converting this word document to a pdf with third party software, but during this conversion I can add special items to the document by coordinate or by looking for certain text in the document. So I would like to be able to either get the simple coordinates of this image or replace the image with a paragraph element whose frame is positioned in roughly the location of this image.

    • Edited by joecar Friday, July 25, 2014 8:30 PM add context to question
    Friday, July 25, 2014 6:13 PM

Answers

  • Hi joecar,

    Sorry for the delay in providing a response. Converting from an ST_RelFromH (ISO/IEC 29500-1:2012 §20.4.3.4) or an ST_RelFromV (§20.4.3.5) other than “page” to “page” is not a trivial operation. The position of the anchor is known based on the position and size of the run or runs that precede it on the page, and you would first need to perform that computation and then use the relative offsets to compute the final positioning of the drawing. You would need to take font faces, sizes, and other formatting into account to determine the final position on the page. Essentially, you would need to provide your own document rendering engine.

    While it’s possible to specify a text frame for a paragraph (§17.3.1.11), you would have to provide page-relative coordinates to ensure that it covers the same area as the image you are replacing. That would require the same computation discussed above. A possible solution might be to replace the image with a text box (§20.4.2.37 and §20.4.2.38), but the text associated with that element is structured in the document differently from a normal paragraph. As a result, your normal method of finding and replacing the paragraph element may not work.

    Best regards,
    Matt Weber | Microsoft Open Specifications Team
    Tuesday, August 26, 2014 4:22 PM

All replies

  • Hi,
    Thank you for this inquiry. One of our team members will investigate this and follow-up soon.

    Regards,
    Edgar

    Friday, July 25, 2014 7:31 PM
    Moderator
  • Hi joecar,

    Sorry for the delay in providing a response. Converting from an ST_RelFromH (ISO/IEC 29500-1:2012 §20.4.3.4) or an ST_RelFromV (§20.4.3.5) other than “page” to “page” is not a trivial operation. The position of the anchor is known based on the position and size of the run or runs that precede it on the page, and you would first need to perform that computation and then use the relative offsets to compute the final positioning of the drawing. You would need to take font faces, sizes, and other formatting into account to determine the final position on the page. Essentially, you would need to provide your own document rendering engine.

    While it’s possible to specify a text frame for a paragraph (§17.3.1.11), you would have to provide page-relative coordinates to ensure that it covers the same area as the image you are replacing. That would require the same computation discussed above. A possible solution might be to replace the image with a text box (§20.4.2.37 and §20.4.2.38), but the text associated with that element is structured in the document differently from a normal paragraph. As a result, your normal method of finding and replacing the paragraph element may not work.

    Best regards,
    Matt Weber | Microsoft Open Specifications Team
    Tuesday, August 26, 2014 4:22 PM