Text Moves to Next Page | Insert Watermark using .NET

Doküman sisteme aktarılır, aspose word ile doküman tekrar oluşturulurken watermark eklenir. Dokümandaki görsellerde kaymalar olduğu görüntülenir. Orjinal doküman 20 sayfadır. Aspose word ile oluşan word dokümanı 23 sayfa oluşur.
Watermark kod bloğu
protected void SetWaterMarkWord(Aspose.Words.Document document)
{
Shape watermark = new Shape(document, ShapeType.TextPlainText);
watermark.Name = “WaterMark”;
// Set up the text of the watermark.
watermark.TextPath.Text = “Okuma Kopyasıdır”;
watermark.TextPath.Bold = true;
watermark.TextPath.Size = 30;
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 = -45;
// Remove the following two lines if you need a solid black text.
watermark.Fill.Color = System.Drawing.Color.LightGreen; // Try LightGray to get more Word-style watermark
watermark.StrokeColor = System.Drawing.Color.LightGreen; // 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;

        // Create a new paragraph and append the watermark to this paragraph.
        Paragraph watermarkPara = new Paragraph(document);
        watermarkPara.AppendChild(watermark);

        foreach (Section sect in document.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);
        }
        // document.Save(uplFile.FileName + "_WaterMark", uzanti.ToLower() == ".doc" ? Aspose.Words.SaveFormat.Doc : Aspose.Words.SaveFormat.Docx);
    }

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

I attached the original file and corrupted file. We are using Aspose.Word.20.12 version. Thanks
YG13691.zip (2.7 MB)

@srmbimser

We suggest you please add the watermark into document using the following code example. Moreover, please read the following article. Hope this helps you.
Working with Watermark

Document doc = new Document(MyDir + "original_doc.doc");
TextWatermarkOptions options = new TextWatermarkOptions()
{
    FontFamily = "Arial",
    FontSize = 36,
    Color = Color.Black,
    Layout = WatermarkLayout.Horizontal,
    IsSemitrasparent = false
};

doc.Watermark.SetText("Okuma Kopyasıdır", options);

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

We have a similar structure to the InsertWatermarkText method in the AddWatermark class in the article you shared. Is there a solution you can suggest for the error in this structure?

@srmbimser

We suggest you please use the code example shared in my previous post. However, if you do not want to use it, you should add watermark shape in the existing paragraph of header of document.

This code snippets adds new paragraph in the header of document. So, you need to get a paragraph of header and add watermark to it.

If your requirement is different, please share some more detail about your query. We will then answer it accordingly.

We created the document with aspose word without using the watermark feature. Space is added in the document and it consists of 23 pages. The original document is 20 pages.

@srmbimser

We have tested the scenario using the latest version of Aspose.Words for .NET 21.4 and have not found the shared issue. Please check the attached output document. 21.4 output.zip (976.4 KB)

Could you please share the code example that you are using along with problematic output document?