I’ve encountered an abnormal behavior for watermark. I’m using aspose.words 17.9 version. Watermark doesn’t appear on my system, whereas it perfectly displays on other fellow developers machines. I don’t know if library is blocking watermark or what’s the reason. Please help me out as same issue occurred in production environment. Also please tell me if MS-Office is mandatory for aspose?
I’m providing my code, I copied from insert watermark example which is available here: https://docs.aspose.com/words/java/add-watermark/
private static void insertWatermarkFormat(Document doc, String watermarkText, Map<String, Object> params) throws Exception {
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
String wmText = "";
String previewText = getStringParamVal("preview",params);
if(!"".equals(previewText)){
wmText = previewText.concat(System.lineSeparator()).concat(watermarkText);
}
else{
wmText = watermarkText;
}
watermark.getTextPath().setText(wmText);
watermark.getTextPath().setFontFamily("Arial");
watermark.setWidth(500);
watermark.setHeight(100);
watermark.setRotation(-40);
watermark.setBehindText(true);
// watermark.getFill().setColor(Color.getHSBColor(198, 5,98));
// watermark.setStrokeColor(Color.getHSBColor(198, 5,98));
watermark.getFill().setColor(Color.lightGray);
watermark.setStrokeColor(Color.lightGray);
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setVerticalAlignment(VerticalAlignment.CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(watermark);
// Insert the watermark into all headers of each document section.
for (Section sect : doc.getSections()) {
// There could be up to three different headers in each section, since we want
// the watermark to appear on all pages, insert into all headers.
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
}
}
private static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, int headerType) throws Exception {
HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);
if (header == null) {
// There is no header of the specified type in the current section, create it.
header = new HeaderFooter(sect.getDocument(), headerType);
sect.getHeadersFooters().add(header);
}
// Insert a clone of the watermark into the header.
header.appendChild(watermarkPara.deepClone(true));
}