Watermark added using Watermark artifact for page containing images is not displayed properly

watermark gets hidden by the images added on the PDF page.

@BALKRUSHNA015478

Please share a sample PDF file along with the complete sample code snippet that you are using to add the watermark. We will test the scenario in our environment and address it accordingly.

@asad.ali
Thanks for quick response.

Here is the code I am trying -
I have attached the input as well as output pdfs , let me know if I am missing something.Demo2.pdf (303.4 KB)
watermark_text.pdf (304.2 KB)

public static void addWatermark() {

	// Open document
	Document doc = new Document(_dataDir + "Demo2.pdf");
	FormattedText formattedText = new FormattedText("Watermark", java.awt.Color.BLUE, FontStyle.Courier,
			EncodingType.Identity_h, true, 72.0F);
	
	for(int i=1; i<=doc.getPages().size(); i++) {
		
		WatermarkArtifact artifact = new WatermarkArtifact();
		artifact.setText(formattedText);
		//artifact.setArtifactHorizontalAlignment(HorizontalAlignment.Center);
		//artifact.setArtifactVerticalAlignment(VerticalAlignment.Center);
		Point waterMarkPos = new Point(200,200);
		artifact.setPosition(waterMarkPos);
		artifact.setBackground(true);
		artifact.setRotation(45);
		artifact.setOpacity(0.5);
		
		doc.getPages().get_Item(i).getArtifacts().add(artifact);
	}
	
	doc.save(_dataDir + "watermark_text.pdf");
}

@BALKRUSHNA015478

You are noticing this behavior because you are setting the watermark in the background. Please use setBackground(false) to render it correctly.

artifact.setBackground(false);

watermark_text.pdf (304.5 KB)

@asad.ali this resolved my issue.

Thank you.

1 Like