Displaying the Watermark ( Image) Behind the pictures in the Word Document

Hi,
Currently we are using the licensed Aspose software for attaching the watermark into the Word document. We are insertng the watermark as a image into the word document. If word document already having any pictures , it is displaying the behing these pictures. How can we dispaly the attached watermark image top of these Pictures in the word document.
Code Using for Inserting the image into the word document:

Shape shape = builder.insertImage("D:\\watermark.jpg");
shape.setName("WaterMark");
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
shape.setVerticalAlignment(VerticalAlignment.CENTER);

Regards,
Dheeraj

Hi
Thanks for your request. Watermark in MS Word document is just a shape inserted in document’s header. The technique of inserting watermarks in a document is described here:
https://docs.aspose.com/words/net/working-with-watermark/
As you can see watermark shape is inserted into the header of the document.
Best regards,

Hi,
We are using JDK1.4 version releated Aspose word jar file (Aspose.Words.jdk14.jar) and attaching the watermark in center of the document . If document contains any pictures, watermark is displaying behind the picture. Is there any way to display the watermark top of the picture. Sample document file is attached. This doc already contains the picture and added the watermark using the Aspose, watermark is displayed the behing the picture.
Code:

Shape shape = builder.insertImage("d:\\prerelease.jpg");
shape.setName("WaterMark");
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
shape.setVerticalAlignment(VerticalAlignment.CENTER);

prerelease.jpg file also attached.
Regards,
Dheeraj

Hi
Thanks for your inquiry. What you are asking for is impossible due to few reasons:

  1. You insert your watermark in the document’s header. All content of document’s header/footer is always behind the main content of the document.
  2. Your watermark is JPEG image. Even if you insert this image on the front of the main content, all content behind this image will be hidden, because JPEG format does not support transparency.

Do you need a watermark on each page, or on the first page only? If you need this watermark on the first page only, then I think, you can achieve what you are asking for. In this case, you can just insert a watermark into the main body.
Best regards,

Hi Andrey,

In the statement, you mention you insert your watermark in the document’s header. Is there another way to handle this? Is it possible to insert the watermark on all pages so that it does go in front of the images? When it is done via the UI of MS Word, it does in fact display in front of the images. If we are overlooking something on how to achieve our client’s results, I would love to hear them.

Thank you very much!
–Mike / Dheeraj

Hi Mike,

Thanks for your request. Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document. That is why we insert a watermark image into a header to repeat this image on each page. So there is no way to determine on which page and where on the page a watermark image should be inserted.
Best regards,

Hi Andrey,
I’m getting the following error when i try to execute the Sample code for watermark. Currently i’m using the JDK1.4 version Aspose jar(Aspose.Words.jdk14.jar). Can you please share the JDK1.4 version wateramark sample code?
Foreach loops are not supported at this language level
Thank you very much.
Regards,
Dheeraj

Hi

Thanks for your request. You can find needed code here:
https://docs.aspose.com/words/net/working-with-watermark/
Best regards,

Hi ,
Still I’m getting the same error at the below mentoned section in the code .
Foreach loops are not supported at this language Level
Code:

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);
}

Attached the Aspose jar file also.
Regards,
Dheeraj

Thanks Andrey for this detail.

Hi

Thank you for additional information. Could you please attach the document you are getting problem with?
Thanks

Hi Andrey,
Please find the test code and Aspose jar file in attached file.
I got this test code from the following URL:
https://docs.aspose.com/words/net/working-with-watermark/
JDK Version: 1.4
Aspose Jar File: Aspose.Words.jdk14.jar
Regards,
Dheeraj

Hi Dheeraj,
Thank you for additional information. I cannot reproduce the problem on my side. Maybe there is something wrong with your TestFile.doc. Could you please attach this document here for testing?
Best regards,

Hi Andrey,
Problem with the Version. when i compiling the code , getting this error.(foreach loops are not supported at this language level). I have changed the logic and used iterator instead of For loop( Aspose Libraries). It’s executed fine and still watermark is displaying the behind the picture.
Changed Code:

SectionCollection sect = doc.getSections();
Iterator it = sect.iterator();
while (it.hasNext())
{
    Section sect1 = (Section) it.next();
    insertWatermarkIntoHeader(watermarkPara, sect1, HeaderFooterType.HEADER_PRIMARY);
    insertWatermarkIntoHeader(watermarkPara, sect1, HeaderFooterType.HEADER_FIRST);
    insertWatermarkIntoHeader(watermarkPara, sect1, HeaderFooterType.HEADER_EVEN);
}

I’m attaching the both source code and doc files. 1) testFile.doc (Source file) 2) test.doc ( Generated target File)

Regards,
Dheeraj

Hi Dheeraj,
Thank you for additional information. It is perfect that you found the way to resolve the problem with error.
As I mentioned earlier in this thread: you insert your watermark in the document’s header. All content of document’s header/footer is always behind the main content of the document.
Best regards,

Thanks Andrey.

So, to close this thread out, is there any possible way to add a watermark to a Word file where the watermark is displayed in front of the images that are embedded in a Word file? We have tried the sample code and it still shows as behind. This may because of the process we are following or it may be because this is how watermarks function in general. We would need the watermark to appear on each page and to be in front of the images embedded in the MS Word file.

Do you know of any way to achieve the above or is this not feasible?

Thank you.
–Mike

Hi Mike,
Thanks for your request. As I mentioned earlier, Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document. That is why we insert a watermark image into a header to repeat this image on EACH page. So there is no way to determine on which page and where on the page a watermark image should be inserted. So I cannot suggest you any way to achieve this.
Best regards,

Thanks Andrey. That is what I figured as well. The customer is trying to do the equiv of Format -->Background --> Printed Watermark from within MS Word and I have let them know that this approach is not supported.

Thank again for your help!
–Mike

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(28)