none
Word OpenXML wp14:anchorId attribute causing Textbox alignement bug RRS feed

  • Question

  • So. Here is a hard question:

    I developed a Word Plugin for Word 2007, and then upgraded it to Word 2010. It was stable in 2007, but, after the upgraded one important function stopped to work, so I had to revert my changes.

    The specific function which stopped takes the selected picture in the document, and adds a textbox by it's side, with specific formatting. (I'll provide the code at the end of the question)

    The final version could be installed in both, 2007 and 2010, version, but would only work in 2007. Until today!... [suspence]

    By accident, one client used the plugin to work on a document on Word 2010, and surprisingly, it managed to work!!

    So I went to investigate the problem. I took a copy o a working document, and a non-working version of the same document, and compared the OpenXML of both.

    Here is what I found:

    Working Document:

    This is a picture markup on the working document:

    <w:drawing>
        <wp:inline distT="0" distB="0" distL="0" distR="0">
            <wp:extent cx="3251200" cy="2285390"/>
            <wp:effectExtent l="19050" t="19050" r="25400" b="19685"/>
            <wp:docPr id="193" name="Imagem 48" descr="Elev. 4"/>
            <wp:cNvGraphicFramePr>
                <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
            </wp:cNvGraphicFramePr>
            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                    <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
                        <pic:nvPicPr>
                            <pic:cNvPr id="0" name=""/>
                            <pic:cNvPicPr/>
                        </pic:nvPicPr>
                        <pic:blipFill>
                            <a:blip r:embed="rId33">
                                <a:lum/>
                            </a:blip>
                            <a:stretch>
                                <a:fillRect/>
                            </a:stretch>
                        </pic:blipFill>
                        <pic:spPr>
                            <a:xfrm>
                                <a:off x="0" y="0"/>
                                <a:ext cx="3251200" cy="2285390"/>
                            </a:xfrm>
                            <a:prstGeom prst="rect">
                                <a:avLst/>
                            </a:prstGeom>
                            <a:noFill/>
                            <a:ln w="19044" cmpd="sng">
                                <a:solidFill>
                                    <a:srgbClr val="333333"/>
                                </a:solidFill>
                                <a:prstDash val="solid"/>
                            </a:ln>
                        </pic:spPr>
                    </pic:pic>
                </a:graphicData>
            </a:graphic>
        </wp:inline>
    </w:drawing>

    NOT Working Document:

    This is the SAME picture markup on the non-working document:

    <w:drawing>
        <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="0FC2E46A" wp14:editId="42C17A65">
            <wp:extent cx="3251200" cy="2285390"/>
            <wp:effectExtent l="19050" t="19050" r="25400" b="19685"/>
            <wp:docPr id="50" name="Imagem 50" descr="Elev. 1"/>
            <wp:cNvGraphicFramePr>
                <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
            </wp:cNvGraphicFramePr>
            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                    <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
                        <pic:nvPicPr>
                            <pic:cNvPr id="0" name=""/>
                            <pic:cNvPicPr/>
                        </pic:nvPicPr>
                        <pic:blipFill>
                            <a:blip r:embed="rId24">
                                <a:lum/>
                            </a:blip>
                            <a:stretch>
                                <a:fillRect/>
                            </a:stretch>
                        </pic:blipFill>
                        <pic:spPr>
                            <a:xfrm>
                                <a:off x="0" y="0"/>
                                <a:ext cx="3251200" cy="2285390"/>
                            </a:xfrm>
                            <a:prstGeom prst="rect">
                                <a:avLst/>
                            </a:prstGeom>
                            <a:noFill/>
                            <a:ln w="19044" cmpd="sng">
                                <a:solidFill>
                                    <a:srgbClr val="333333"/>
                                </a:solidFill>
                                <a:prstDash val="solid"/>
                            </a:ln>
                        </pic:spPr>
                    </pic:pic>
                </a:graphicData>
            </a:graphic>
        </wp:inline>
    </w:drawing>

    The only difference, is in the second line, where the working document reads:

    <wp:inline distT="0" distB="0" distL="0" distR="0">

    and the other reads:

    <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="0FC2E46A" wp14:editId="42C17A65">

    So! The not working document picture have two extra attributes wp14:anchorId and wp14:editId.

    The Function:

    This is the method that adds and format the textbox to the picture.

    Sub AddTextBox(ByVal picture As Word.InlineShape)
      Dim textBox As Word.Shape =
        ActiveDocument.Shapes.AddTextbox(
            Orientation:=Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
            
            
            Width:=MarginWidth - picture.Width - 10,
            Height:=picture.Height,
            Anchor:=picture.Range.Paragraphs(1).Range)
    
    With textBox
        .RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin
        .RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionParagraph
    
        .Line.DashStyle = Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid
        .Line.BackColor.RGB = RGB(255, 255, 255)
        .Line.Style = Microsoft.Office.Core.MsoLineStyle.msoLineSingle
        .Line.Weight = 0.25
    
        .LockAnchor = True
    End With
    EndSub

    The Problem:

    The method above, as you can see, aligns the textbox to the Top of the paragraph wher the image is. The image is inline, therefore, the textbox top aligns to the top of the image. This is what happens in word 2007 and on the referred working document.

    The problem is: When I run this method on the not working document, the textbox ends up aligned with the top of the PAGE. Without margin.

    This working document is exceptional. All the others behave like the not-working one in Word 2010.

    I've researched MSDN documentation, and there's no info about those attributes.

    So please:

    1. What are the attributes wp14:anchorId and wp14:editId?
    2. And how to make Word stop generating them?
    3. Or how to stop textboxes goingo to the top of the page when these attributes exist.

    Thanks very much in advance.


    • Edited by LucioMarques Thursday, November 15, 2012 4:27 PM
    • Moved by Max Meng Friday, November 16, 2012 7:14 AM (From:Word IT Pro Discussions)
    Thursday, November 15, 2012 4:26 PM

All replies

  • Hi LucioMarques,

    Thanks for posting in the MSDN Forum.

    I will involve some experts into your thread to see whether they can help you. There might be some time delay, appreciate for your patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, November 16, 2012 7:34 AM
    Moderator
  • Hi Lucio

    A follow-up question:

    Is the working document in "Compatibility Mode" and the non-working documents not?

    The other thing to check, please, is File/Options/Trust Center/Privacy Options: "Store random numbers to improve Combine accuracy". Is this different in the environment that generated the working document (turned off would be my guess)?


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, November 16, 2012 8:40 AM
    Moderator