Can you help me convert this code that i had been using word automation to use aspose as i cnanot seem to do it.
Alternative is there a better way to add a watermark effect to certian pages?
Thank you
'''
''' Adds a watermark to the word document section givern
'''
''' Current Header Section to Anchor the WaterMark too
''' Created by JPK on 16/08/2006
'''
''' I could not use Word Art as there is a bug in all versions of office that prevent the anchor
''' poperty for being used by office.
'''
''' For this reason I have used a Transparent Textbox behind the text with Gray text inside for the water mark effect
'''
'''
'''
Private Sub AddMark(ByVal CurrentHeader As Word.HeaderFooter)
Dim w As Word.Shape = CurrentHeader.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 25, 230, 475, 302, CurrentHeader.Range)
w.TextFrame.TextRange.Text = "Matchtech" + Environment.NewLine + "Copy"
w.Fill.Visible = Office.MsoTriState.msoFalse
w.Fill.Transparency = 0.0#
w.Line.Style = Office.MsoLineStyle.msoLineSingle
w.Line.Visible = Office.MsoTriState.msoFalse
w.TextFrame.TextRange.Text = "Matchtech" + Environment.NewLine + "Copy"
w.TextFrame.TextRange.Font.Name = "Arial Black"
w.TextFrame.TextRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
w.TextFrame.TextRange.Font.ColorIndex = Word.WdColorIndex.wdGray25
w.TextFrame.TextRange.Font.Size = 75
End Sub
Please check the StampAndWatermarkDemo class in C:\Program Files\Aspose\Aspose.Words\Demos\Aspose.Words.Demos.WinForms project. It has an example of how watermark can be applied.
The water mark I require is accross the centre of the page and is large gray text.
The way i had previosly achived it by placing a textbox in the header (so it apeared on each page) but setting the location to the centre of the screen.
I cnnot see from the sample how to achive a water mark that is not an image int he centre of the pages?
Please make a sample document with desired watermark using MS Word and attach it here. I will try to make an Aspose.Words code for you - creating the similar watermark.
Find a sample file attached.
We stich together several documents and then insert a second copy of all the docuements with the watermarks for the recipient to return.
Thank you
John K
Here is the code:
DocumentBuilder builder = new DocumentBuilder(doc);
for (int sectionNum = 0; sectionNum < doc.Sections.Count; sectionNum++)
{
builder.MoveToSection(sectionNum);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Shape shape = new Shape(doc, ShapeType.TextBox);
shape.WrapType = WrapType.Through;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Column;
shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.None;
shape.Left = 25;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
shape.VerticalAlignment = VerticalAlignment.None;
shape.Top = 230;
shape.Width = 475;
shape.Height = 302;
builder.InsertNode(shape);
Paragraph para = new Paragraph(doc);
shape.AppendChild(para);
builder.MoveTo(para);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Font.Name = "Arial Black";
builder.Font.Size = 75;
builder.Font.Color = Color.FromArgb(0xc0, 0xc0, 0xc0);
builder.Writeln("Matchtech");
builder.Write("Copy");
}
Hope this helps,
That worked with a bit of tweaking
Had to make shape.WrapType = WrapType.Through; shape.WrapType = WrapType.None; and set shape.StrokeColor = Color.White to hide the border.
Thanks
John Kilmister
Ok, great! One more tip though. Hiding borders, setting their color to white is genrally not recommended. What if yor document had blue background? Then the borders will become visible again. In this particular case you can just set shape.Stroke.On to false.
Hope this helps,
I thought I had this all sorted however tested pointed out an issue and I cannot seem to resolve it.
Although the water mark looks fine in word (shows in Grey) the text is actually in white. This becomes apparent if you try to edit the watermark by editing the headers or more importantly if you print out the document.
I am setting the text colour (see below) but this has no effect.
Private Sub AddMark(ByVal CurrentHeader As Word.HeaderFooter)
Dim w As Word.Shape = CurrentHeader.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 25, 230, 475, 302, CurrentHeader.Range)
w.TextFrame.TextRange.Text = "Matchtech" + Environment.NewLine + "Copy"
w.Fill.Visible = Office.MsoTriState.msoFalse
'w.Fill.Transparency = 0.0#
w.Line.Style = Office.MsoLineStyle.msoLineSingle
w.Line.Visible = Office.MsoTriState.msoFalse
w.TextFrame.TextRange.Font.Name = "Arial Black"
w.TextFrame.TextRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
w.TextFrame.TextRange.Font.ColorIndex = Word.WdColorIndex.wdGray25
w.TextFrame.TextRange.Font.Size = 75
End Sub
Not really sure what you speak about. Did you try the .NET sample above? It produces the correct result to me. Please elaborate your request.
If you have look at the attached document the water mark looks fine, however if you print it out it does not appear.
This is because no matter what color i make the text it always adds it in white (but word shows all headers in gray when on screen).
Could you please post .NET code you are currently using to insert a watermark into this document?
A template is made up of amny files some of which have a water mark and some that do not
Below is the code we use to build up our final document it then calls the AddMark function (shown earlier in the post) to add the mark if required.
For i As Integer = 1 To template.TemplateFiles.Count - 1
range = WordApp.Application.ActiveDocument.Sections.Add.Range
range.InsertFile(CStr(template.TemplateFiles(i).Path))
'Add WaterMark Print
If template.TemplateFiles(i).AddMTGWaterMark Then
For Each section As Word.Section In range.Sections
For Each CurrentHeader As Word.HeaderFooter In section.Headers
AddMark(currentheader)
Next
Next
End If
Next
Thank you
This is a Word Automation sample. What .NET code involving Aspose.Words are you using?
I found the bug.
I was looking at the old code as as you correcly pointed out so when i looked at the corect code it was obvious that I had been setting the colour to somehting that was too light.
Sorry for that one.
John