Inserting an image to word using Open XML with behind text property RRS feed

  • Question

  • Hi,

    I have managed to insert an image to word document using open xml but i want this picture has the behind text property. In my case there should be text on the newly inserted picture but with inline property text moves the picture.

    Is there a way to do that?

    Thanks in advance,

    Friday, November 9, 2012 9:55 AM


  • Hi Burakuytun

    Please show us the code that inserts the picture so that we correctly understand what kind of picture this is. Word supports more than one kind of graphic. Graphics can be "inline" or with "text flow formatting". Only the latter kind can be positioned behind text...

    The first kind appears in the underlying WordOpenXML like this:

      <wp:inline wp14:editId="0D4E8ABC" wp14:anchorId="7C8B7683" distR="0" distL="0" distB="0" distT="0">

    The second like this:

      <wp:anchor distR="114300" distL="114300" distB="0" distT="0" allowOverlap="1" layoutInCell="1" locked="0" behindDoc="1" relativeHeight="251658240" simplePos="0">

    Notice wp:inline vs. wp:anchor. The positioning behind the text is set by the attribute behindDoc where 1 means it is positioned behind the document text. This must be used in combination with <wp:wrapNone/>, which is a child element of wp:anchor.

    The Open XML SDK equivalent of the Anchor element is DocumentFormat.OpenXML.Drawing.WordProcessing.Anchor; BehindDoc is a property of the Anchor class.

    The equivalent of wp:WrapNone is DocumentFormat.OpenXml.Drawing.Wordprocessing.WrapNone

    You'll find the explanation of the behavior as I outlined in the description of WrapNone: http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.wordprocessing.wrapnone(office.14).aspx

    Cindy Meister, VSTO/Word MVP, my blog

    • Proposed as answer by 许阳(无锡) Monday, November 12, 2012 6:01 AM
    • Marked as answer by 许阳(无锡) Thursday, November 15, 2012 5:21 AM
    Saturday, November 10, 2012 9:57 AM