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

Free Support Forum - aspose.com

How to set image border for page using Java

Hi Team,

Our client has water mark requirements to have center text (three characters) and border text ( a string of characters). The border text shoud appear all along of borders of word document where as the center text appears in center. Is this possible with Aspose Java API for Word?
I can see new DocumentBuilder().getParagraphFormat().getBorders().getByBorderType(BorderType.TOP); gives me a reference to the border, but there is no way to add text to border. Please advise


Could you please ZIP and attach your input and expected output documents? We will then provide you more information about your query.

please find the source and expected end result attached.
aspose-pdf.zip (248.9 KB)


Thanks for sharing the document. We are working over your query and will get back to you soon.

Please also note that there is a water mark in center which is going behind the text for the particular word file i was testing with . In other instances it was in foreground and therefore visible.


Could you please ZIP and attach the images that you inserted into expected output document? We will write the code according to your requirement and then share it with you. Thanks for your cooperation.

tahir.b64.png (46.6 KB)
Hi Tahir, i am using the attached png as background. Our end game is HTML so if you can enable this background, as water mark, in pdf to HTML conversion, that will work better for us. We were trying word as an intermediate conversion just to get things going.

Do open the attached with paint or some editor as default windows viewer does not render it well


Thanks for sharing the image. You can move the cursor to the paragraph on each page of document and insert the image. Following code example shows how to insert this image into document according to your requirement.

Document doc = new Document(MyDir + "source.docx");

DocumentBuilder documentBuilder = new DocumentBuilder(doc);
Shape shape = documentBuilder.InsertImage(MyDir + @"tahir.b64.png");

shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.VerticalAlignment = VerticalAlignment.Center;
shape.Width = doc.FirstSection.PageSetup.PageWidth;
shape.Height = doc.FirstSection.PageSetup.PageHeight;

doc.Save(MyDir + "20.2.docx");

Moreover, the LayoutCollector.GetStartPageIndex method returns 1-based index of the page where node begins. You can use this method for paragraphs to get the page number, move the cursor to the paragraph, and insert the image on each page.