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 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.
I tried with 20.7 version but still no luck. Please find the attached pdf file to apply watermark on.Test Document to convert to pdf.PDF (58.1 KB)
The code -> FontRepository.findFont(getWatermarkFontName())
Returns the instance of the Font but the end result does not show watermark printed on PDF file.
We will surely investigate the issue that you are facing and share our feedback with you. However, as requested earlier, would you please confirm that all windows fonts are installed in the system where you are facing the issue?
We have logged an investigation ticket as PDFJAVA-39670 in our issue tracking system for further anlaysis against your case. We will investigate the reasons behind this issue and keep you informed with the status of ticket resolution. Please be patient and spare us some time.
The earlier logged ticket is not yet resolved. It will be investigated and resolved on first come first serve basis. We will inform you as soon as we have some definite updates regarding its resolution. Please give us some time.