Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
tartancli
 
Posts: n/a
Default How do i insert a watermark into a Word Document programatically (

Hi,

I'm trying to insert a watermark witha a Word Add-in. I'm using a variant
of Paul Stubbs code that i found from a Google. The method I'm using is as
follows:

private void addWatermark(Word.Document doc, string WatermarkText)
{



doc.Application.ActiveWindow.View.Type = Word.WdViewType.wdPrintView;

doc.Sections[1].Range.Select();
doc.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekCurrentPageHeader;

Word.Selection Selection = doc.Application.Selection;
Word.Shape wmShape;

//Create the watermark shape
Object missing = Type.Missing;
wmShape = Selection.HeaderFooter.Shapes.AddTextEffect(
Microsoft.Office.Core.MsoPresetTextEffect.msoTextE ffect1,
WatermarkText, "Times New Roman", 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 = "PowerPlusWaterMarkObject1";
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 = doc.Application.InchesToPoints(2.82f);
wmShape.Width = doc.Application.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.wdRelativeHorizo ntalPositionMargin;
wmShape.RelativeVerticalPosition =
Word.WdRelativeVerticalPosition.wdRelativeVertical PositionMargin;
wmShape.Left = (float)Word.WdShapePosition.wdShapeCenter;
wmShape.Top = (float)Word.WdShapePosition.wdShapeCenter;

//set focus back to document
doc.Application.ActiveWindow.ActivePane.View.SeekV iew =
Word.WdSeekView.wdSeekMainDocument;


} // end addWatermark

The problem i have is that I get an exception at line:
wmShape.WrapFormat.AllowOverlap = -1;

this excpetion indicated that the method or property is not available
because the drawing operation cannot be applied to the current selection?????

Any help greatly appreciated!!! Thnx
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
take yet another lesson from wordperfect "reveal codes" wordperfect is superior Microsoft Word Help 5 May 11th 09 07:58 PM
How can Word display full path of a file in the title bar? SAsif Microsoft Word Help 1 January 26th 06 04:32 PM
Does Word have a QuickCorrect/Quick Word option like WordPerfect? CW New Users 2 December 20th 05 05:54 PM
In Word, how do I surpress headers and footers on page 2 Bill Microsoft Word Help 1 December 15th 05 06:13 PM
How do I create a Word form like corel WP merge documents? dlee_at_mmsgov Microsoft Word Help 2 October 8th 05 06:29 AM


All times are GMT +1. The time now is 03:51 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"