com.groupdocs.watermark

Interfaces

Classes

Exceptions

com.groupdocs.watermark

Class DocumentPart

    • Method Detail

      • findImages

        public final WatermarkableImageCollection findImages(ImageSearchCriteria searchCriteria)

        Finds images according to specified search criteria. The search is conducted in objects specified in Document.SearchableObjects.

        Parameters:
        searchCriteria - The search criteria to use.
        Returns:
        The collection of found images.
      • findImages

        public final WatermarkableImageCollection findImages()

        Finds all images in the document. The search is conducted in objects specified in Document.SearchableObjects.

        Returns:
        The collection of found images.

        This example demonstrates how to add watermark to all images in a document of any supported type.

        Document document = Document.load("D:\\input.doc");
         // Initialize text or image watermark.
         TextWatermark watermark = new TextWatermark("DRAFT", new Font("Arial", 19));
         // Find all images in the document.
         WatermarkableImageCollection images = document.findImages();
         // Add watermark.
         for (WatermarkableImage watermarkableImage : images)
         {
             watermarkableImage.addWatermark(watermark);
         }
         // Save changes.
         document.save("D:\\output.doc");
         document.close();
         
      • findWatermarks

        public final PossibleWatermarkCollection findWatermarks(SearchCriteria searchCriteria)

        Finds possible watermarks according to specified search criteria. The search is conducted in objects specified in Document.SearchableObjects.

        Parameters:
        searchCriteria - The search criteria to use.

        This example demonstrates how to find and remove all possible watermarks containing particular text or image from a document of any supported type.

        Document document = Document.load("D:\\input.doc");
         ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("D:\\logo.png");
         Pattern regex = Pattern.compile("CompanyName", Pattern.CASE_INSENSITIVE);
         TextSearchCriteria textSearchCriteria = new TextSearchCriteria(regex);
         PossibleWatermarkCollection watermarks = document.findWatermarks(textSearchCriteria.or(imageSearchCriteria));
         watermarks.clear();
         document.save("D:\\output.doc");
         document.close();
         
        Returns:
        The collection of possible watermarks.
      • findWatermarks

        public final PossibleWatermarkCollection findWatermarks()

        Finds all possible watermarks in the document. The search is conducted in objects specified in Document.SearchableObjects.

        Returns:
        The collection of possible watermarks.
      • addWatermark

        public void addWatermark(Watermark watermark)

        Adds a watermark to this DocumentPart.

        Parameters:
        watermark - The watermark to add to the document.

        This example demonstrates how to add image and text watermark to a document of any supported type.

        Document document = Document.load("D:\\input.pdf");
         TextWatermark textWatermark = new TextWatermark("DRAFT", new Font("Arial", 19));
         textWatermark.setHorizontalAlignment(HorizontalAlignment.Center);
         textWatermark.setVerticalAlignment(VerticalAlignment.Top);
         textWatermark.setConsiderParentMargins(true);
         textWatermark.setForegroundColor(Color.getRed());
         textWatermark.setBackground(true);
         textWatermark.setOpacity(0.5);
         document.addWatermark(textWatermark);
         ImageWatermark imageWatermark = new ImageWatermark("D:\\draft.png");
         imageWatermark.setHorizontalAlignment(HorizontalAlignment.Center);
         imageWatermark.setVerticalAlignment(VerticalAlignment.Bottom);
         imageWatermark.setConsiderParentMargins(true);
         imageWatermark.setBackground(true);
         imageWatermark.setOpacity(0.5);
         document.addWatermark(imageWatermark);
         imageWatermark.close();
         document.save("D:\\output.pdf");
         document.close();