Quantcast
Viewing all articles
Browse latest Browse all 7205

How to add a watermark with a text or image to the document

This example illustrates how you can add a watermark to the document. The main idea is to add a corresponding Floating Object (TextBox or Picture) to the header section (see SubDocument essentials - simple examples). Take special note of the TextRenderer.MeasureText Method, which is used to calculate the correct size of a textual watermark.

See Also:
SubDocument.InsertPicture Method
SubDocument.InsertTextBox Method

Question Comments

Added By: TRAINEAU SOIZIC at: 10/24/2012 3:42:24 AM    

Don't work for me with the last build :
the text on the page (the real one : not the watermark text) disapears from left to right when zooming ... try to set the zoom at 200 %

Added By: TRAINEAU SOIZIC at: 10/24/2012 3:45:14 AM    

in fact it seems that it is a horizontal scrollbar problem ... try to zoom and play with Hscrolling

Added By: Anders Wang at: 9/4/2014 11:57:01 PM    

But, After you save as it to word, You can see the layout is corrupted by the watermark. So how to deal with it?

Added By: Elliot (DevExpress Support) at: 9/5/2014 6:32:17 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T147935: Corrupted document layout. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Anders Wang at: 9/23/2015 10:53:07 PM    

Hi,
for text watermark with chinese font (Simhei), your following shapesize calculaition code caused clipped watermark. The text cannot be fully displayed. Could you please help us? Thanks.
          Size sizeInPixels = TextRenderer.MeasureText(text, measureFont);
          shape.Size = new SizeF(Units.PixelsToDocumentsF(sizeInPixels.Width, richEditControl.DpiX), Units.PixelsToDoc

Added By: Andrey (DevExpress Support) at: 9/24/2015 8:18:12 AM    

Hello,
The issue occurs depends on the value returned by the standard System.Window.Forms.TextRenderer.MeasureText method and doesn't rely on our products.
To resolve the issue, increase a shape size as follows:

[C#]
shape.TextBox.Document.EndUpdateCharacters(cp);shape.TextBox.HeightRule=TextBoxSizeRule.Auto;shape.RotationAngle=-45;SizesizeInPixels=TextRenderer.MeasureText(text,measureFont);shape.Size=newSizeF(Units.PixelsToDocumentsF(sizeInPixels.Width,richEditControl.DpiX)+ 10,Units.PixelsToDocumentsF(sizeInPixels.Height,richEditControl.DpiY));


Please try this solution and let me know your results. 

Added By: Anders Wang at: 9/24/2015 6:23:53 PM    

Hi,
Really? Do you have check "Units.PixelsToDocumentsF"?

Added By: Andrey (DevExpress Support) at: 9/25/2015 4:17:41 AM    

Hello,
I have researched the issue and came to the conclusion that the cause of the issue is rounding of the shape size on its rendering.
To resolve the issue, set the RichEditControl.LayoutUnit property to DocumentLayoutUnit.Document in the example's SetTextWatermark method without any other modifications.

Added By: Anders Wang at: 9/27/2015 6:37:10 PM    

Hi,
Set  RichEditControl.LayoutUnit doesn't work for me. The Text Water mark (Simhei)  are still clipped.

Added By: Andrey (DevExpress Support) at: 9/28/2015 12:37:18 AM    

Hello,
To process your recent post more efficiently, I created a separate ticket on your behalf: T294138: The E4184 example doesn't work properly with the 'Simhei' font. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Andrew Bingham 2 at: 2/29/2016 3:44:23 AM    This code throws an exception  "specified document position or range belongs to other document or subdocument" Added By: Andrey (DevExpress Support) at: 2/29/2016 4:09:31 AM    

Hello,
To process your recent post more efficiently, I created a separate ticket on your behalf: T350978: 'Specified document position or range belongs to other document or subdocument' error occurs on running the E4184 example. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.


Viewing all articles
Browse latest Browse all 7205

Trending Articles