com.groupdocs.watermark

Interfaces

Classes

Exceptions

com.groupdocs.watermark

Class Document

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, Closeable, AutoCloseable
    Direct Known Subclasses:
    CellsDocument, DiagramDocument, EmailDocument, ImageDocument, PdfDocument, SlidesDocument, WordsDocument


    public abstract class Document
    extends DocumentPart
    implements com.aspose.ms.System.IDisposable, Closeable

    Represents a document where a watermark can be placed.

    This example demonstrates how to load and save a document of any supported format.

    // Load a document from a file.
      Document document = Document.load("D:\\input.pdf");
      
      // Use methods of Document class to add or remove watermarks.
      // Save changes.
      document.save("D:\\output.pdf");
      document.close();
      
    • Method Detail

      • getDefaultSearchableObjects

        public static SearchableObjects getDefaultSearchableObjects()

        Gets the document objects that are to be included in a watermark search by default. This setting should be configured before document instance creation. It has no effect on already existing instances. To configure searchable objects for a particular document instance, use SearchableObjects property.

        Returns:
        The document objects that are to be included in a watermark search by default.

        This example demonstrates how to remove hyperlinks with a particular url from a document of any supported format.

        String inputFolder = "D:\\docs\\input\\";
          String outputFolder = "D:\\docs\\output\\";
          // Specify that only hyperlinks should be searched for.
          SearchableObjects searchableObjects = new SearchableObjects();
          searchableObjects.setWordsSearchableObjects(WordsSearchableObjects.Hyperlinks);
          searchableObjects.setCellsSearchableObjects(CellsSearchableObjects.Hyperlinks);
          searchableObjects.setDiagramSearchableObjects(DiagramSearchableObjects.Hyperlinks);
          searchableObjects.setPdfSearchableObjects(PdfSearchableObjects.Hyperlinks);
          searchableObjects.setSlidesSearchableObjects(SlidesSearchableObjects.Hyperlinks);
          
          Document.setDefaultSearchableObjects(searchableObjects);
          File[] files = new File(inputFolder).listFiles();
          for (File file : files)
          {
              if (file.isFile())
              {
                  Document doc = Document.load(file.getAbsolutePath());
              
                  // Specify the url to be searched for.
                  TextSearchCriteria criteria = new TextSearchCriteria("someurl.com", false);
                  PossibleWatermarkCollection watermarks = doc.findWatermarks(criteria);
                  // Remove all found hyperlinks.
                  watermarks.clear();
                  // Save changes.
                  doc.save(outputFolder + file.getName());
                  doc.close();
              }
          }
          
      • setDefaultSearchableObjects

        public static void setDefaultSearchableObjects(SearchableObjects value)

        Sets the document objects that are to be included in a watermark search by default. This setting should be configured before document instance creation. It has no effect on already existing instances. To configure searchable objects for a particular document instance, use SearchableObjects property.

        Parameters:
        value - The document objects that are to be included in a watermark search by default.

        This example demonstrates how to remove hyperlinks with a particular url from a document of any supported format.

        String inputFolder = "D:\\docs\\input\\";
          String outputFolder = "D:\\docs\\output\\";
          // Specify that only hyperlinks should be searched for.
          SearchableObjects searchableObjects = new SearchableObjects();
          searchableObjects.setWordsSearchableObjects(WordsSearchableObjects.Hyperlinks);
          searchableObjects.setCellsSearchableObjects(CellsSearchableObjects.Hyperlinks);
          searchableObjects.setDiagramSearchableObjects(DiagramSearchableObjects.Hyperlinks);
          searchableObjects.setPdfSearchableObjects(PdfSearchableObjects.Hyperlinks);
          searchableObjects.setSlidesSearchableObjects(SlidesSearchableObjects.Hyperlinks);
          
          Document.setDefaultSearchableObjects(searchableObjects);
          File[] files = new File(inputFolder).listFiles();
          for (File file : files)
          {
              if (file.isFile())
              {
                  Document doc = Document.load(file.getAbsolutePath());
              
                  // Specify the url to be searched for.
                  TextSearchCriteria criteria = new TextSearchCriteria("someurl.com", false);
                  PossibleWatermarkCollection watermarks = doc.findWatermarks(criteria);
                  // Remove all found hyperlinks.
                  watermarks.clear();
                  // Save changes.
                  doc.save(outputFolder + file.getName());
                  doc.close();
              }
          }
          
      • getSearchableObjects

        public final SearchableObjects getSearchableObjects()

        Gets the document objects that are to be included in a watermark search. Note, this property also specifies document objects which are used in image search. For more information see DocumentPart.FindWatermarks(), DocumentPart.FindWatermarks(SearchCriteria), DocumentPart.FindImages() and DocumentPart.FindImages(ImageSearchCriteria) methods.

        Returns:
        The document objects that are to be included in a watermark search.

        This example demonstrates how to remove all XObjects and Artifacts from a pdf document.

        Document doc = Document.load("D:\\input.pdf");
          
          Specify that only XObjects and Artifacts should be searched for.
          doc.getSearchableObjects().setPdfSearchableObjects(PdfSearchableObjects.XObjects | PdfSearchableObjects.Artifacts); 
          
          PossibleWatermarkCollection watermarks = doc.findWatermarks();
          // Remove all found hyperlinks.
          watermarks.clear();
          
          // Save changes.
          doc.save("D:\\output.pdf");
          doc.close();
          
      • setSearchableObjects

        public final void setSearchableObjects(SearchableObjects value)

        Sets the document objects that are to be included in a watermark search. Note, this property also specifies document objects which are used in image search. For more information see DocumentPart.FindWatermarks(), DocumentPart.FindWatermarks(SearchCriteria), DocumentPart.FindImages() and DocumentPart.FindImages(ImageSearchCriteria) methods.

        Parameters:
        value - The document objects that are to be included in a watermark search.

        This example demonstrates how to remove all XObjects and Artifacts from a pdf document.

        Document doc = Document.load("D:\\input.pdf");
          
          Specify that only XObjects and Artifacts should be searched for.
          doc.getSearchableObjects().setPdfSearchableObjects(PdfSearchableObjects.XObjects | PdfSearchableObjects.Artifacts); 
          
          PossibleWatermarkCollection watermarks = doc.findWatermarks();
          // Remove all found hyperlinks.
          watermarks.clear();
          
          // Save changes.
          doc.save("D:\\output.pdf");
          doc.close();
          
      • load

        public static Document load(String filePath)

        Loads a new document from the specified file.

        Parameters:
        filePath - The file path to load document from.
        Returns:
        Instance of appropriate descendant of Document class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • load

        public static Document load(String filePath,
                    LoadOptions loadOptions)

        Loads a new document from the specified file.

        Parameters:
        filePath - The file path to load document from.
        loadOptions - Additional options to use when loading a document.
        Returns:
        Instance of appropriate descendant of Document class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • load

        public static Document load(InputStream stream)

        Loads a new document from the specified stream.

        Parameters:
        stream - The stream to load document from.
        Returns:
        Instance of appropriate descendant of Document class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • load

        public static Document load(InputStream stream,
                    LoadOptions loadOptions)

        Loads a new document from the specified stream.

        Parameters:
        stream - The stream to load document from.
        loadOptions - Additional options to use when loading a document.
        Returns:
        Instance of appropriate descendant of Document class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • getInfo

        public static DocumentInfo getInfo(InputStream stream)

        Gets the information about the format of a document stored in the stream.

        Parameters:
        stream - The stream containing a document.

        This example demonstrates how to get information about a document of any supported type.

        InputStream stream = new FileInputStream("D:\\test.ppt");
         DocumentInfo docInfo = Document.getInfo(stream);
         System.out.println(docInfo.getFileFormat());
         System.out.println(docInfo.isEncrypted());
         stream.close();
         
        Returns:
        The DocumentInfo instance that contains detected information.
      • getInfo

        public static DocumentInfo getInfo(String filePath)

        Gets the information about the format of a document stored in the file.

        Parameters:
        filePath - The file path.

        This example demonstrates how to get information about a document of any supported type.

        DocumentInfo docInfo = Document.getInfo("D:\\test.ppt");
         System.out.println(docInfo.getFileFormat());
         System.out.println(docInfo.isEncrypted());
         
        Returns:
        The DocumentInfo instance that contains detected information.
      • load

        public static <TDocument extends Document> TDocument load(Class<TDocument> documentType,
                                                  String filePath)

        Loads a new document from the specified file.

        Parameters:
        filePath - The file path to load document from.
        documentType - Expected document type (according to specified file type).

        TDocument: Expected document type (according to specified file type).

        Returns:
        Instance of TDocument class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • load

        public static <TDocument extends Document> TDocument load(Class<TDocument> documentType,
                                                  String filePath,
                                                  LoadOptions loadOptions)

        Loads a new document from the specified file.

        Parameters:
        filePath - The file path to load document from.
        loadOptions - Additional options to use when loading a document.
        documentType - Expected document type (according to specified file type).

        TDocument: Expected document type (according to specified file type).

        Returns:
        Instance of TDocument class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • load

        public static <TDocument extends Document> TDocument load(Class<TDocument> documentType,
                                                  InputStream stream)

        Loads a new document from the specified stream.

        Parameters:
        stream - The stream to load document from.
        documentType - Expected document type (according to specified file type).

        TDocument: Expected document type (according to specified stream content).

        Returns:
        Instance of TDocument class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • load

        public static <TDocument extends Document> TDocument load(Class<TDocument> documentType,
                                                  InputStream stream,
                                                  LoadOptions loadOptions)

        Loads a new document from the specified stream.

        Parameters:
        stream - The stream to load document from.
        loadOptions - Additional options to use when loading a document.
        documentType - Expected document type (according to specified file type).

        TDocument: Expected document type (according to specified stream content).

        Returns:
        Instance of TDocument class.
        Throws:
        UnsupportedFileTypeException - Supplied document type is not supported.
      • save

        public final void save(String filePath)

        Saves the document to the specified file location.

        Parameters:
        filePath - The file path to save the document data to.
      • save

        public final void save(OutputStream stream)

        Saves the document to the specified stream.

        Parameters:
        stream - The stream to save the document data to.
      • dispose

        public final void dispose()

        Disposes the current instance.

        Specified by:
        dispose in interface com.aspose.ms.System.IDisposable
      • dispose

        protected void dispose(boolean disposing)

        Disposes the current instance.

        Parameters:
        disposing - True to release both managed and unmanaged resources; false to release only unmanaged resources.