We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word docs cretion

Hi , we r trying to watermark a word doc which has a table in it with out text,then we r unable to apply water mark

Hi,


Thanks for your inquiry. Are you using the code from the following article?

How to Add a Watermark to a Document

If yes then please attach your input document and output document showing the undesired behavior here for testing. If not then please also share simple console application (source code without compilation errors) for our reference. We will then investigate the issue on our end and provide you more information.

Best regards,

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,


Thanks for your inquiry. After an initial test with Aspose.Words for .NET 15.12.0 and the following code I was unable to reproduce this issue on my side.

private static void InsertWatermarkText(Document doc, string watermarkText)

{

// 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));

}


Hope, this helps.

Best regards,