We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Image watermark width issue

We are finding the same problem. We recently upgraded and the code below used to set the watermark to the width of the page - this used to work perfectly but it now no longer does so, it leaves a small gap.

Shape watermark = p_builder.insertImage(p_image);

Our watermark was just a green image to force the background to green so the gap is very important.

just to be clear this is on aspose words for java v19.2


To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Your share Aspose.Words version that generates the correct output.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

watermark.zip (6.5 KB)

Have attached the watermark image and the resulting output document. Generated using v19.2 of Aspose Words for java using the below code. This used to result in a completely green output whereas after upgrade to v19.2 a strip of white space is now left on the right margin.

Document t_doc = new Document();
DocumentBuilder builder = new DocumentBuilder(t_doc);
ByteArrayOutputStream pt_out = new ByteArrayOutputStream();
String t_input = “

just some text
PageSetup t_setup = builder.getPageSetup();
Shape watermark = builder.insertImage(“C:\work\watermark.png”);
Paragraph watermarkPara = new Paragraph(t_doc);
HeaderFooter header = builder.getCurrentSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
if (header == null) {
// There is no header of the specified type in the current section, create it.
header = new HeaderFooter(t_doc, HeaderFooterType.HEADER_FIRST);
// Insert a clone of the watermark into the header.

Just to add, we would be interested to hear whether you have any suggested workarounds - essentially, we need certain documents (generated from HTML) to have a completely green background (incl. margin and footer areas) - the way we previously achieved this was through a watermark.


You can set the document’s background color using following code example.

Document t_doc = new Document();

Shape shapeRectangle = new Shape(t_doc, ShapeType.RECTANGLE);

t_doc.save(MyDir + "output.docx");

If you want to insert the image as you are doing in your code, please set the image’s width and height as shown in following code snippet.

watermark.setWidth(t_setup.getPageWidth() + t_setup.getLeftMargin() + t_setup.getRightMargin());
watermark.setHeight(t_setup.getPageHeight() + t_setup.getTopMargin() + t_setup.getBottomMargin());

Thank you Manzoor - that seems to work