Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

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

$
0
0

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"?


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>