none
Text watermarks word 2010 fully patched not centralised on a page RRS feed

  • Question

  • Hi

    Im adding a text watermark to a document in c#.  All is fine except the positioning of the watermark.  I cannot seem to fathom how to get the watermark placed central on the page in the same way it is as if you did the following steps manually within word:

    Select Page Layout->Watermark->Custom Watermark

    Then select text watermark, change text to DRAFT and ENSURE Diagonal is selected.

    The watermark is placed central diagonally in the document.

    The following code nicely inserts the watermark diagonally but it is not central to the page.  I can only think margins or and headers and footers are affecting this - so I have tested with an out of box document with out of box margins etc and its still does not place it in the correct place.  I would like it to be exactly like it is out of the box as described above.

    This is an extract of the code (see below).  Grateful for any help.

    Anna

    private static void AddWatermark(string WatermarkText, Microsoft.Office.Interop.Word.Application wordApp)
    {
    object missing = System.Reflection.Missing.Value;

    Word.Selection Selection = wordApp.Selection;

    Word.Shape wmShape;

    //Select the section
    wordApp.ActiveDocument.Sections[1].Range.Select();
    wordApp.ActiveWindow.ActivePane.View.SeekView =Word.


    WdSeekView.wdSeekCurrentPageHeader;


    //Create the watermark shape

    wmShape = Selection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
    WatermarkText,"Ariel", 1,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoFalse,0, 0,
    ref missing);


    //Set all of the attributes of the watermark


    wmShape.Select(ref missing);
    wmShape.Name = "WaterMark";
    wmShape.TextEffect.NormalizedHeight = Microsoft.Office.Core.MsoTriState.msoFalse;
    wmShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
    wmShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
    wmShape.Fill.Solid();
    wmShape.Fill.ForeColor.RGB = (int)Word.WdColor.wdColorGray25;
    wmShape.Fill.Transparency = 0.5f;
    wmShape.Rotation = 315.0f;

    wmShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
    wmShape.Height = wordApp.InchesToPoints(2.82f);
    wmShape.Width = wordApp.InchesToPoints(5.64f);
    wmShape.WrapFormat.AllowOverlap = -1; //true

    wmShape.WrapFormat.Side = Word.WdWrapSideType.wdWrapBoth;
    wmShape.WrapFormat.Type = Word.WdWrapType.wdWrapNone; //3
    wmShape.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;

    wmShape.RelativeVerticalPosition =Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
    wmShape.Left =float)Word.WdShapePosition.wdShapeCenter;
    wmShape.Top = (float)Word.WdShapePosition.wdShapeCenter;

    //set focus back to document
    wordApp.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
    }

    Friday, July 18, 2014 11:26 AM

All replies

  • Hi Anna

    Which version of word are you using?

    If you record a macro while performing the steps that work for you (just the positioning, really), then compare the properties recorded in the macro to those in your code do you see anything useful?


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 18, 2014 4:12 PM
    Moderator
  • Hi,

    According to your description, I think your code is just based on a recording macro in Word. I try to reproduce your issue with your code, but the inserted watermark is in the central of the page as followed.

    So I suspect the issue is related to the setting of the document or your application. Have you tried to create a new document to test it? I suggest you sharing your sample Word document through OneDrive to help use reproduce and troubleshoot.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 21, 2014 8:53 AM
    Moderator