Hi
We have a license with Aspose and the order id is 230926145941
The watermark is not appearing in the first page in Word in the licensed version using Aspose Word API for Java.
In trial version the watermark is showing in the first page.
I will attach the sample file where the issue exists. Also will attach the code snippet.
doc.zip (33.9 KB)
private boolean watermarkTextWordFile (File wordFile, String watermarkText, String fileSuffix, String outputDirectory) throws Exception {
boolean watermarkedFile = false;
String fileName="";
try {
fileName = wordFile.getName();
String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);
String filePath = wordFile.getPath();
String fileExtension = ".docx";
if (!fileName.endsWith(".docx")) {
fileExtension = ".doc";
}
//to apply license
com.aspose.words.License license = new com.aspose.words.License();
license.setLicense("Aspose.Total.Java.lic");
com.aspose.words.Document doc = new Document(filePath);
com.aspose.words.Shape watermark = new com.aspose.words.Shape(doc,com.aspose.words.ShapeType.TEXT_PLAIN_TEXT);
//changes done for including watermark text in cover page also of doc 12/12/2023
TextWatermarkOptions opt = new TextWatermarkOptions();
opt.setColor(Color.red);
opt.setFontSize(12);
opt.setLayout(WatermarkLayout.HORIZONTAL);
doc.getWatermark().setText(watermarkText,opt);
for (com.aspose.words.Shape s : (Iterable<com.aspose.words.Shape>)doc.getChildNodes(NodeType.SHAPE, true))
{
s.setVerticalAlignment(com.aspose.words.VerticalAlignment.BOTTOM);
}
String watermarkedFilePath = outputDirectory + fileSeparator + fileNameWithOutExt + fileSuffix + fileExtension;
doc.save(watermarkedFilePath);
// logger.debug("watermarkedFilePath: " + watermarkedFilePath);
infolog.info("watermarkedFilePath: " + watermarkedFilePath);
watermarkedFile = true;
}
catch (Exception ex) {
// logger.error("watermarkTextWordFile ex:", ex);
errlog.error("watermarkTextWordFile ex:" + ex + ":" + fileName);
}
return watermarkedFile;
}
Pasted the code above
Thanks
Rama
@Rama_Menon Unfortunately, I cannot reproduce the problem on my side using the latest 23.12 version of Aspose.Words and the following code:
Document doc = new Document("C:\\Temp\\in.doc");
TextWatermarkOptions opt = new TextWatermarkOptions();
opt.setColor(Color.red);
opt.setFontSize(12);
opt.setLayout(WatermarkLayout.HORIZONTAL);
doc.getWatermark().setText("My Cool Watermark", opt);
for (com.aspose.words.Shape s : (Iterable<com.aspose.words.Shape>)doc.getChildNodes(NodeType.SHAPE, true))
{
if (s.getName().startsWith("PowerPlusWaterMarkObject") || s.getName().startsWith("WordPictureWatermark"))
s.setVerticalAlignment(com.aspose.words.VerticalAlignment.BOTTOM);
}
doc.save("C:\\Temp\\out.doc");
Hi ,
This issue is happening only in licensed version
Trial works perfectly fine
Regards
Rama
@Rama_Menon I have tested with licensed version of Aspose.Words and watermark is properly show on all pages of the document. Could you please attach the output document produced on your side here for our reference?
@alexey.noskov
Had already uploaded the word file. (doc.zip)
Again uploading here.
doc.zip (33.9 KB)
Thanks
Rama
@Rama_Menon Is this your input or output document? I have used the attached document as an input and the watermark is properly inserted on each page of the document. If the attached document is your output document, please attach your input document. Both input and output documents are required for analysis.
@alexey.noskov Uploading the license file we are using.
Can you run using this, in one of your word files to see if it is missing to watermark the cover page.
If so, why usage of this license file causes the watermark to be missed in the cover page.
licensefile.zip (751 Bytes)
@Rama_Menon Thank you for additional information I have tested with the licensed version and watermark is properly added on all pages.
Could you please attach your input and output documents once again, just in case you have uploaded wrong document in the initial post. But please attach both input and output documents.
@alexey.noskov Attaching the original word doc file(with name suffixed with _Orig)and the watermarked file for your investigation .Also attaching the license file.
With this license file, the first page of all the word docs are not getting watermarked.
docs.zip (67.6 KB)
license.zip (751 Bytes)
Thanks
Rama
@Rama_Menon Unfortunately, the problem is still not reproducible on my side using the following code:
Document doc = new Document("C:\\Temp\\1034553_007_Orig.doc");
TextWatermarkOptions opt = new TextWatermarkOptions();
opt.setColor(Color.red);
opt.setFontSize(12);
opt.setLayout(WatermarkLayout.HORIZONTAL);
doc.getWatermark().setText("VIASAT PROPRIETARY - L3HARRIS' RIGHTS DEFINED UNDER THE APA AND IP/SDR LICENSE AGREEMENTS, DATED 1/3/2023", opt);
for (com.aspose.words.Shape s : (Iterable<com.aspose.words.Shape>)doc.getChildNodes(NodeType.SHAPE, true))
{
if (s.getName().startsWith("PowerPlusWaterMarkObject") || s.getName().startsWith("WordPictureWatermark"))
{
s.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
s.setVerticalAlignment(com.aspose.words.VerticalAlignment.BOTTOM);
}
}
doc.save("C:\\Temp\\out.doc");
out.zip (29.9 KB)
Please provide your code that will allow us to reproduce the problem on our side.
@alexey.noskov
ok.Sending the code again.
code.zip (906 Bytes)
@Rama_Menon Unfortunately, the problem is still not reproducible on my side. Your code is almost the same as code I have provide in my previous answer.
I have inspected 1034553_007.doc
document, which is your output document and it looks like it was not produced by Aspose.Words or was postprocessed. Could you please make sure that the watermark is not removed from your document while document postprocessing on your side?