com.groupdocs.watermark

Interfaces

Classes

Exceptions

com.groupdocs.watermark

Class WordsDocument

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public class WordsDocument
    extends Document

    Class representing Word document (doc, docx etc) where watermark should be placed.

    This example demonstrates how to load and save Word document of any supported type.

    WordsDocument document = Document.load(WordsDocument.class, "D:\\input.doc");
     // Use addWatermark method to add watermark to all sections.
     // Use the collection of sections to add watermark to a particular section.
     // Save changes.
     document.save("D:\\output.doc");
     document.close();
     
    • Method Detail

      • getSections

        public final WordsSectionCollection getSections()

        Gets the collection of all sections of this WordsDocument.

        Returns:
        The collection of all sections of this WordsDocument.

        This example demonstrates how to add watermark to a particular section.

        WordsDocument document = Document.load(WordsDocument.class, "D:\\input.doc");
         // Initialize text or image watermark.
         TextWatermark watermark = new TextWatermark("DRAFT", new Font("Arial", 19));
         // Add watermark to a particular section.
         document.getSections().get_Item(0).addWatermark(watermark);
         // Save changes.
         document.save("D:\\output.doc");
         document.close();
         
      • getPageCount

        public final int getPageCount()

        Gets the number of pages in the document.

        Returns:
        The number of pages in the document.
      • encrypt

        public final void encrypt(String password)

        Encrypts the document.

        Parameters:
        password - The password that will be required to open the document.
      • decrypt

        public final void decrypt()

        Decrypts the document.

      • addWatermark

        public final void addWatermark(Watermark watermark,
                        int pageNumber)

        Adds a watermark to a particular pages of this WordsDocument. Do not use this method to add watermarks to all pages in loop. This may lead to significant decrease of performance. Use AddWatermark(Watermark) instead.

        Parameters:
        watermark - The watermark to add to the document.
        pageNumber - The page number. Correct values are in range from 1 to PageCount.
      • addWatermark

        public void addWatermark(Watermark watermark)

        Adds a watermark to all sections of this WordsDocument. This method assumes that watermark offset and size are measured in points (if they are assigned).

        Overrides:
        addWatermark in class DocumentPart
        Parameters:
        watermark - The watermark to add to the document.
      • addWatermark

        public final void addWatermark(Watermark watermark,
                        WordsShapeSettings shapeSettings)

        Adds a watermark to all sections of this WordsDocument. This method assumes that watermark offset and size are measured in points (if they are assigned).

        Parameters:
        watermark - The watermark to add to the document.
        shapeSettings - Settings that should be applied to the watermark.
      • addTextWatermark

        public final void addTextWatermark(TextWatermark watermark,
                            WordsTextEffects effects)

        Adds a text watermark to all sections of this WordsDocument. This method assumes that watermark offset and size are measured in points (if they are assigned).

        Parameters:
        watermark - The text watermark to add to the document.
        effects - Text effects that should be applied to the watermark.
      • addTextWatermark

        public final void addTextWatermark(TextWatermark watermark,
                            WordsTextEffects effects,
                            WordsShapeSettings shapeSettings)

        Adds a text watermark to all sections of this WordsDocument. This method assumes that watermark offset and size are measured in points (if they are assigned).

        Parameters:
        watermark - The text watermark to add to the document.
        effects - Text effects that should be applied to the watermark.
        shapeSettings - Shape settings that should be applied to the watermark.
      • addImageWatermark

        public final void addImageWatermark(ImageWatermark watermark,
                             WordsImageEffects effects)

        Adds an image watermark to all sections of this WordsDocument. This method assumes that watermark offset and size are measured in points (if they are assigned).

        Parameters:
        watermark - The image watermark to add to the document.
        effects - Image effects that should be applied to the watermark.
      • addImageWatermark

        public final void addImageWatermark(ImageWatermark watermark,
                             WordsImageEffects effects,
                             WordsShapeSettings shapeSettings)

        Adds an image watermark to all sections of this WordsDocument. This method assumes that watermark offset and size are measured in points (if they are assigned).

        Parameters:
        watermark - The image watermark to add to the document.
        effects - Image effects that should be applied to the watermark.
        shapeSettings - Shape settings that should be applied to the watermark.
      • protect

        public final void protect(int protectionType,
                   String password)

        Protects the document from changes and sets a protection password. To have the content of the document editable use appropriate method of adding watermark with WordsLockType.AllowOnlyFormFields or WordsLockType.ReadOnlyWithEditableContent parameter.

        Parameters:
        protectionType - Specifies the protection type for the document.
        password - The password to protect the document with.
      • unprotect

        public final void unprotect()

        Removes protection from the document regardless of the password.