Free Support Forum - aspose.com

Unable to add watermark to the PDF on MacOS Catalina and Amazon Linux 2 operating systems

Hello Team, we are facing issue regarding watermark is not printed on the created PDF.

One example, we are converting word file to pdf using Aspose library. The pdf is generated successfully but without the watermark. The same code base works fine on the windows machine. We also tried to use the font families which are available on the mentioned operating systems but still no luck. We are working with java 8 and soon will be upgrading to Java 11.

Aspose dependencies in pom.xml:

com.aspose
aspose-cells
19.1


com.aspose
aspose-words
19.1
jdk16


com.aspose
aspose-pdf
18.12


com.aspose
aspose-slides
18.12
jdk16


com.aspose
aspose-diagram
18.12
jdk16


com.aspose
aspose-tasks
18.11
jdk17


com.aspose
aspose-barcode
18.12
jdk17


com.aspose
aspose-email
18.9
jdk16


com.aspose
aspose-imaging
18.11


com.aspose
aspose-note
19.1
jdk17


com.aspose
aspose-cad
18.3
jdk16

Following code is written for watermark printing:
private TextStamp getBodyTextStamp(String watermarkText) {
FormattedText formatText = new FormattedText(watermarkTextArray[0]);
TextStamp textStamp = new TextStamp(formatText);
textStamp.setRotateAngle((double)getWatermarkAngle());
textStamp.setHorizontalAlignment(getWatermarkHorizontalAlignment());
textStamp.setVerticalAlignment(getWatermarkVerticalAlignment());
textStamp.getTextState().setFont(FontRepository.findFont(getWatermarkFontName()));
textStamp.getTextState().setFontSize((float)getWatermarkFontSize());
textStamp.setBackground(false);
textStamp.getTextState().setForegroundColor(Color.fromRgb(java.awt.Color.decode(getWatermarkColor())));
if (isWatermarkOutlineOnly()) {
textStamp.setDraw(isWatermarkOutlineOnly());
textStamp.setOutlineOpacity(.getWatermarkOpacity());
textStamp.setOpacity(0.0D);
} else {
textStamp.setOpacity(.getWatermarkOpacity());
}

        return textStamp;
    } else {
        return null;
    }
}

private void appendStamp(Document pdfDocument, TextStamp textStamp) {
if (textStamp != null) {
PageCollection pageCollection = pdfDocument.getPages();
for(int i = 1; i <= pageCollection.size(); ++i) {
pageCollection.get_Item(i).addStamp(textStamp);
}

    }
}

Could you please help us to find the root cause?

Thank you!

@abhave

Could you kindly try to use latest version of the APIs e.g. Aspose.PDF for Java 20.7. Also, please try to install all windows fonts in your system where issue is occuring. In case it still persists, please share your sample PDF document with us so that we can test the scenario in our environment and address it accordingly.