How to Add Watermark to a MS Word Document inside Android Applications

This technical tip explains how to add a watermark to a document in Microsoft Word document inside Android Applications. Sometimes you need to insert a watermark into a Word document, for instance if you would like to print a draft document or mark it as confidential. In Microsoft Word, you can quickly insert a watermark using the Insert Watermark command. Not many people using this command realize that such “watermark” is just a shape with text inserted into a header or footer and positioned in the centre of the page. While Aspose.Words doesn't have a single insert watermark command like Microsoft Word, it is very easy to insert any shape or image into a header or footer and thus create a watermark of any imaginable type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//your code here...[Java Code Sample]
 
package AddWatermark;
import java.awt.Color;
import java.io.File;
import java.net.URI;
import com.aspose.words.Document;
import com.aspose.words.Shape;
import com.aspose.words.ShapeType;
import com.aspose.words.RelativeHorizontalPosition;
import com.aspose.words.RelativeVerticalPosition;
import com.aspose.words.WrapType;
import com.aspose.words.VerticalAlignment;
import com.aspose.words.HorizontalAlignment;
import com.aspose.words.Paragraph;
import com.aspose.words.Section;
import com.aspose.words.HeaderFooterType;
import com.aspose.words.HeaderFooter;
public class Program
{
    public static void main(String[] args) throws Exception
    {
        // Sample infrastructure.
        URI exeDir = Program.class.getResource("").toURI();
        String dataDir = new File(exeDir.resolve("../../Data")) + File.separator;
        Document doc = new Document(dataDir + "TestFile.doc");
        insertWatermarkText(doc, "CONFIDENTIAL");
        doc.save(dataDir + "TestFile Out.doc");
    }
    /**
     * Inserts a watermark into a document.
     *
     * @param doc The input document.
     * @param watermarkText Text of the watermark.
     */
    private static void insertWatermarkText(Document doc, String watermarkText) throws Exception
    {
        // Create a watermark shape. This will be a WordArt shape.
        // You are free to try other shape types as watermarks.
        Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
X

Url: http://www.aspose.com/docs/display/wordsandroid/How+to++Add+a+Watermark+to+a+Document

Language: Java | User: Sheraz Khan | Created: Jul 8, 2015 | Tags: insert a watermark into a Word document add watermark Microsoft Word create a watermark of any imaginable type Create a watermark shape Word Android API Place watermark in the page center