TextStamp as Watermark- make it unselectable

How to make this happen?


I used a TextStamp as watermark and added it to the document.

However, i can select it. Is there a way to somehow like flatten it to the document so that it will not be selectable?

Hi Chit,

Thanks for your inquriy. TextStamp class has a property (bool Draw) for the purpose. If this property is true stamp will be drawn with graphic operators instead of text. This prevents from selecting text (also stamp text can not be extracted from the document). Please check following code snippet, hopefully it will help you to accomplish the task.

Document doc = **new** Document();

Page page = doc.getPages().add();

TextStamp stamp = **new** TextStamp(**new** FormattedText("Aspose.Pdf for Java", java.awt.Color.*BLACK*, "Arial", EncodingType.*Identity_h*, **true**, 32));

stamp.setHorizontalAlignment(HorizontalAlignment.*Center*);

stamp.setVerticalAlignment(VerticalAlignment.*Center*);

//set this property to true in order to make stamp which is drawn with set of operators.

stamp.setDraw(**true**);

page.addStamp(stamp);

doc.save(“output.pdf”);

Best Regards,

Hi Chit,

Thanks for your email. In case of multi-line stamp you need to add text lines in FormattedText object as following, it will help you to accomplish the task.

FormattedText ft = new FormattedText((String) watermark.get(0), java.awt.Color.LIGHT_GRAY, 4, 5, false,FONT_SIZE, SPACING);

ft.addNewLineText((String) watermark.get(1));

ft.addNewLineText((String) watermark.get(2));

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal


The method i sent to you already does that

my issue is that if I call TextStamp.setDraw(true) so that the text drawn will not be selectable, only 1 line is printed instead of the 3 lines

Hi Chit,


Thanks for your feedback. I have tested the scenario with setDraw property and noticed the reported issue. We have already logged a ticket PDFJAVA-36390 in our issue tracking system for rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,