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

Free Support Forum - aspose.com

Page Index missing after watermarking for some pages

Hello,


I try to watermark a file with this code:
Aspose.Words.Drawing.Shape watermark = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText);

// Set up the text of the watermark.
watermark.TextPath.Text = watermarkText;
watermark.TextPath.FontFamily = “Arial”;
watermark.Width = 500;
watermark.Height = 20;

watermark.Rotation = 0;
watermark.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Top;
watermark.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
watermark.Fill.Color = System.Drawing.Color.Red;
watermark.StrokeColor = System.Drawing.Color.Red;

watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
watermark.WrapType = WrapType.None;

Aspose.Words.Paragraph watermarkPara = new Aspose.Words.Paragraph(doc);
watermarkPara.AppendChild(watermark);

// Insert the watermark into all headers of each document section.
foreach (Aspose.Words.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);
}

public static void InsertWatermarkIntoHeader(Aspose.Words.Paragraph watermarkPara, Aspose.Words.Section sect, HeaderFooterType headerType)
{
Aspose.Words.HeaderFooter header = sect.HeadersFooters[headerType];

if (header == null)
{
// There is no header of the specified type in the current section, create it.
header = new Aspose.Words.HeaderFooter(sect.Document, headerType);
sect.HeadersFooters.Add(header);
}

// Insert a clone of the watermark into the header.
header.AppendChild(watermarkPara.Clone(true));
}


The page index disappear on some pages. See attachment

Can you help me??

Regards,
Laurent
Hi Laurent,

Thanks for your inquiry. The headers and footers of documents are linked to the previous section. Please use the following highlighted code to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "TestIndice.docx");

Aspose.Words.Drawing.Shape watermark = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText);

// Set up the text of the watermark.

watermark.TextPath.Text = "Water Mark";

watermark.TextPath.FontFamily = "Arial";

watermark.Width = 500;

watermark.Height = 20;

watermark.Rotation = 0;

watermark.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Top;

watermark.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;

watermark.Fill.Color = System.Drawing.Color.Red;

watermark.StrokeColor = System.Drawing.Color.Red;

watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;

watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;

watermark.WrapType = WrapType.None;

Aspose.Words.Paragraph watermarkPara = new Aspose.Words.Paragraph(doc);

watermarkPara.AppendChild(watermark);

Aspose.Words.Section sect = doc.FirstSection;

InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);

InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);

InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven);

doc.Save(MyDir + "Out.docx");

Thanks you very munch.


Its working.

Have a nive day.

Laurent
Hi Laurent,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.