none
Making an image WrapThrough when inserting into Word Document with openxml 2.0 RRS feed

  • Question

  • Here is my code, what am I doing wrong?

    private static void AddImageToBody(Body mainBody, string relationshipId, long imageWidthEMU, long imageHeightEMU, UInt32 ID1, UInt32 ID2)
      {
       string GraphicDataUri = "http://schemas.openxmlformats.org/drawingml/2006/picture"; 
       double imageWidthInInches = imageWidthEMU / 914400.0; 
       double imageHeightInInches = imageHeightEMU / 914400.0; 
       long horizontalWrapPolygonUnitsPerInch = (long)(21600L / imageWidthInInches); 
       long verticalWrapPolygonUnitsPerInch = (long)(21600L / imageHeightInInches); 
    
       //Define the reference of the image
         var element =   
          new Drawing(
          new DW.Inline(
           new DW.Extent()
           {
            Cx = imageWidthEMU,
            Cy = imageHeightEMU
           },
           new DW.EffectExtent() 
           {
            LeftEdge = 19050L, 
            TopEdge = 0L,  
            RightEdge = 9525L, 
            BottomEdge = 0L 
           },
           new DW.WrapThrough()
           {
            WrapText = DW.WrapTextValues.BothSides
           
           },
           new DW.DocProperties() 
           {
            Id = ID1,
            // (UInt32Value)1U,
            Name = relationshipId,
            Description = "Description_" + relationshipId 
           },
           new DW.NonVisualGraphicFrameDrawingProperties(  
            new A.GraphicFrameLocks()
            { NoChangeAspect = true }), 
            new A.Graphic( 
             new A.GraphicData(
              new PIC.Picture(
               new PIC.NonVisualPictureProperties(
                new PIC.NonVisualDrawingProperties() 
                {
                 Id = ID2,
                 // (UInt32Value)2U,
                 Name = relationshipId,
                 Description = "Description_" + relationshipId 
                }, 
                new PIC.NonVisualPictureDrawingProperties()),  
                new PIC.BlipFill(         
                 new A.Blip(         
                  new A.BlipExtensionList(     
                   new A.BlipExtension()     
                   {          
                    Uri = GraphicDataUri    
                   })         
                   )
                   {
                    Embed = relationshipId,   
                    CompressionState = A.BlipCompressionValues.Print 
                   },
                   new A.Stretch(         
                    new A.FillRectangle())),     
                    new PIC.ShapeProperties(     
                     new A.Transform2D(      
                      new A.Offset() { X = 0L, Y = 0L }, 
                      new A.Extents() { Cx = imageWidthEMU, Cy = imageHeightEMU }), 
                      new A.PresetGeometry(          
                       new A.AdjustValueList()        
                       ) { Preset = A.ShapeTypeValues.Rectangle }))   
                       ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }) 
                       )
                       {
                        DistanceFromTop = (UInt32Value)0U,  
                        DistanceFromBottom = (UInt32Value)0U, 
                        DistanceFromLeft = (UInt32Value)0U,  
                        DistanceFromRight = (UInt32Value)0U  
                       });
       //Append the reference to body, the element should be in a Run. 
       mainBody.Append(new Paragraph (new ParagraphProperties (new Justification() { Val = JustificationValues.Right}), (new Run(element)))); 
    
    
    Tuesday, December 14, 2010 5:00 PM

Answers

  • Hi Sean,

    On looking into your code, i found one thing.

    You are creating Inline drawing instead of Anchor drawing. The wrapping style is only applied to the image of type Anchor (i.e.) Absolutely positioned image, wrapping will not applied to the inline picture.

    Can you try by changing inline image as anchored image and let me know if this helps.

    Regards,
    Vijay


    Regards, Vijay
    • Proposed as answer by Vijay Srinivasan Thursday, December 16, 2010 11:04 AM
    • Marked as answer by Bruce Song Wednesday, December 22, 2010 11:16 AM
    Tuesday, December 14, 2010 7:46 PM

All replies

  • Hi Sean,

    On looking into your code, i found one thing.

    You are creating Inline drawing instead of Anchor drawing. The wrapping style is only applied to the image of type Anchor (i.e.) Absolutely positioned image, wrapping will not applied to the inline picture.

    Can you try by changing inline image as anchored image and let me know if this helps.

    Regards,
    Vijay


    Regards, Vijay
    • Proposed as answer by Vijay Srinivasan Thursday, December 16, 2010 11:04 AM
    • Marked as answer by Bruce Song Wednesday, December 22, 2010 11:16 AM
    Tuesday, December 14, 2010 7:46 PM
  • Sorry for the delay. Great! Thanks I will try it.
    Tuesday, January 11, 2011 3:45 PM