Hi,
I am facing problem with adding the watermark to the PDF file. My goal is to have not selectable, visible watermark in my pdf file.
I am using TextStamp to add watermark to my pdf file, but it is not visible. Funny thing is that I can select this text, copy it to notepad and there it is. I know that to fix that, I have to use setBacground(false), then I see my watermark, but I can still select it, and copy. I do not want to have ability to select watermark to the user. Then I use setDraw(true), and true - I can not longer select this watermark but it looks very ugly. Is there any fix for that?. I just want to have a watermark in the background that is not selectable. I have tried with TextStamp and with WatermarkArtifact and still nothing - to be honest I do not know what is the suggested solution for that, I have tried them both. Here is a snipped of my code :
private byte[] addWatermarkToPdf(byte[] data) {
com.aspose.pdf.Document pdfDocument = null;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
pdfDocument = new com.aspose.pdf.Document(new ByteArrayInputStream(data));
TextStamp textStamp = new TextStamp("Watermark text");
textStamp.setBackground(true);
textStamp.setWidth(558.35);
textStamp.setHeight(93.05);
textStamp.setRotateAngle(-315);
textStamp.setOpacity(0.5);
textStamp.getTextState().setFont(new FontRepository().openFont("C:\\myFont.ttf"));
textStamp.getTextState().setFontSize(14.0F);
textStamp.getTextState().setForegroundColor(Color.fromArgb(222, 222, 222));
textStamp.setHorizontalAlignment(HorizontalAlignment.Center);
textStamp.setVerticalAlignment(VerticalAlignment.Center);
for (int Page_counter = 1; Page_counter <= pdfDocument.getPages().size(); Page_counter++) {
pdfDocument.getPages().get_Item(Page_counter).addStamp(textStamp);
}
} catch (Exception e) {
log.error("Error while adding watermark to pdf", e);
return output.toByteArray();
}
pdfDocument.save(output, SaveFormat.Pdf);
return output.toByteArray();
}
I am using Aspose.Total for Java v 17.10
cheers,
Pawel