Adding watermark causes header/footer to create a new line

Good day!

I’m trying to insert a watermark text using:

https://docs.aspose.com/words/net/working-with-watermark/

The watermark insert just fine, it’s just that, the header has a new line inserted. Or if I change the code to insert watermark using FOOTER type, the footer produces another line.

You could recreate this by using a document with “Page Numbers” and insert a watermark programmatically.

We really need to insert the watermark seamlessly without extra lines.

Thanks!

Hello
Thanks for your request. Could you please attach your input and output documents here? I will investigate the issue and provide you more information.
Best regards,

Hi,

I tried to add the following lines:

watermarkPara.getParagraphFormat().setSpaceAfter(0);
watermarkPara.getParagraphFormat().setSpaceBefore(0);
watermarkPara.getParagraphFormat().setLineSpacing(0);
watermarkPara.getParagraphFormat().setNoSpaceBetweenParagraphsOfSameStyle(true);

It seems to be ok. Thanks!

Hi
Thanks for your request. The problem occurs because with the watermark you also insert paragraph, which contains this watermark shape. That is why you see the additional line break.
As a workaround, you can try inserting watermark shape into the existing paragraphs in the header/footer or specify small font size of the paragraph with watermark to decrease its influence to document’s layout:

Paragraph watermarkPara = new Paragraph(docBuilder.Document);
watermarkPara.ParagraphBreakFont.Size = 1;
watermarkPara.AppendChild(watermark);

Hope this helps.
Best regards.

Thank you for the quick reply.

This was really helpful.

Thanks again, Alexey!