Hi,
Please open the documents, water mark is applied only to first page not to the rest.
This is the code we are using:
private static void InsertWatermarkIntoPage(string file, System.Drawing.Image image, WatermarkLocationType WatermarkLocation, bool isViewer)
{
Aspose.Words.Document doc = new Aspose.Words.Document(file);
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
Aspose.Words.Layout.LayoutCollector collector = new Aspose.Words.Layout.LayoutCollector(doc);
Aspose.Words.Paragraph anchorPara = null;
//
// Tempoarary set the image size to the actual image size.
//
int myImageWidth = image.Width;
int myImageHeight = image.Height;
double myImageRatio = (double)myImageHeight / (double)image.Width;
double myMaxLineLength;
double myMaxImageWidth;
//shape.Fill.Opacity = AlphaFill;
int pageIndex = 1;
foreach (Aspose.Words.Section section in doc.Sections)
{
foreach (Aspose.Words.Paragraph para in section.Body.Paragraphs)
{
if (collector.GetStartPageIndex(para) == pageIndex)
{
anchorPara = para;
Aspose.Words.Rendering.PageInfo docPage = doc.GetPageInfo(pageIndex - 1);
// Insert a floating picture.
Aspose.Words.Drawing.Shape shape = builder.InsertImage(image);
shape.Remove();
shape.WrapType = Aspose.Words.Drawing.WrapType.None;
//Get the document page information.
double myWidth = docPage.WidthInPoints;
//
// Determine the maximum line length. This may changed based
// on the location of the watermark.
//
myMaxLineLength = myWidth;
//
// Determine the maximum image width.
//
myMaxImageWidth = myMaxLineLength;
myImageWidth = (int)myMaxImageWidth;
myImageHeight = (int)(myImageWidth * myImageRatio);
// Determine the location of the watermark image.
//
shape.Height = myImageHeight;
shape.Width = myImageWidth;
shape.RelativeHorizontalPosition = Aspose.Words.Drawing.RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = Aspose.Words.Drawing.RelativeVerticalPosition.Page;
shape.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;
shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
// shape.Left =
shape.Rotation = -45;
anchorPara.AppendChild(shape);
pageIndex++;
}
}
}
Hi,
{
// Create a watermark shape. This will be a WordArt shape.
// You are free to try other shape types as watermarks.
Shape watermark = new Shape(doc, ShapeType.TextPlainText);
// Set up the text of the watermark.
watermark.TextPath.Text = watermarkText;
watermark.TextPath.FontFamily = "Arial";
watermark.Width = 500;
watermark.Height = 100;
// Text will be directed from the bottom-left to the top-right corner.
watermark.Rotation = -40;
// Remove the following two lines if you need a solid black text.
watermark.Fill.Color = Color.Gray; // Try LightGray to get more Word-style watermark
watermark.StrokeColor = Color.Gray; // Try LightGray to get more Word-style watermark
// Place the watermark in the page center.
watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
watermark.WrapType = WrapType.None;
watermark.VerticalAlignment = VerticalAlignment.Center;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.AppendChild(watermark);
// Insert the watermark into all headers of each document section.
foreach (Section sect in doc.Sections)
{
// There could be up to three different headers in each section, since we want
// the watermark to appear on all pages, insert into all headers.
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven);
}
}
private static void InsertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, HeaderFooterType headerType)
{
HeaderFooter header = sect.HeadersFooters[headerType];
if (header == null)
{
// There is no header of the specified type in the current section, create it.
header = new HeaderFooter(sect.Document, headerType);
sect.HeadersFooters.Add(header);
}
// Insert a clone of the watermark into the header.
header.AppendChild(watermarkPara.Clone(true));
}