Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This page explains how to work with watermarks in Word documents.
This topic discusses how to work programmatically with watermark using Aspose.Words. A watermark is a background image that displays behind the text in a document. A watermark can contain a text or an image represented by the Watermark class.
Try online
You can try this functionality with our Free online document watermark.
In Microsoft Word, a watermark can easily be inserted in a document using the Insert Watermark command. Aspose.Words provides the watermark class to add or remove watermark in documents. Aspose.Words provides the WatermarkType enumeration defining three possible types of watermarks (Text, Image, and None) to work with.
The following code example demonstrates how to insert a text watermark in a document by defining TextWatermarkOptions using the setText() method:
The following code example demonstrates how to insert an image watermark in a document by defining ImageWatermarkOptions using the setImage() method:
Image watermark can be inserted as image, string, or stream.
The watermark can also be inserted using shape class as well. It is very easy to insert any shape or image into a header or footer and thus create a watermark of any imaginable type.
The following code example inserts a watermark into a Word document:
The Watermark class provides the remove method to remove the watermark from a document.
The following code example shows how to remove a watermark from documents:
If the watermarks are added using the Shape class object then to remove the watermark from a document you have to set only the name of watermark shape during inserting and then remove watermark shape by an assigned name.
The following code example show you how to set the name of the watermark shape and remove it from the document:
Sometimes you need to insert a watermark/image into a table’s cell and display it outside the table, you can use the isLayoutInCell() property. This property gets or sets a flag indicating whether the shape is displayed inside a table or outside of it. Note that this property works only when you optimize the document for Microsoft Word 2010 using the optimizeFor() method.
The following code example shows how to use this property:
Q: How can I add a watermark to only a specific page in a document?
A: Insert the watermark into a header/footer that is linked only to the desired page (e.g., using a different first‑page header). Set the watermark’s Name property so you can later remove or modify it without affecting other pages.
Q: Can I control the opacity of a text or image watermark?
A: Not with an exact opacity value. For text watermarks, TextWatermarkOptions.isSemitrasparent(true) makes the text semi-transparent; for image watermarks, ImageWatermarkOptions.isWashout(true) applies a washout effect.
Q: How do I remove a watermark that was added without specifying a name?
A: Call doc.getWatermark().remove(); it removes the watermark added with Watermark.setText or Watermark.setImage, with or without a name. For a watermark shape you added yourself, naming it (watermark.setName("MyMark")) makes it easy to find and remove later.
Q: Is it possible to add a watermark inside a table cell and have it appear behind the cell’s text?
A: Yes. Call isLayoutInCell(false) on the watermark shape and ensure the document is optimized for Word 2010 (doc.getCompatibilityOptions().optimizeFor(MsWordVersion.WORD_2010)). This places the watermark outside the cell layout while keeping it visually aligned with the table.
Q: Can I add a watermark to a document that is being generated in memory (without saving to disk first)?
A: Absolutely. Create a Document instance from a stream or from scratch, apply the watermark using the Watermark class, and then save the document directly to a ByteArrayOutputStream or any other output stream. No intermediate file is required.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.