Filter in File or Stream Mode

To filter files using the methods in the Filter class

  1. Instantiate a Filter object using either the default constructor or the constructor that sets the output character set and filter flags:

    1. Use the default constructor Filter(). For example:

      objFilter = new Filter();
    2. Use the constructor Filter(string OutputCharSet, UInt32 filterFlags).For example:

      objFilter = new Filter(outputCharSet, FilterConstant.FilterFlagConstant.FILTERFLAG_OOPLOGON);

    The Filter flags provide instructions on how to process a file or stream. For example, they specify whether an error log is generated during filtering (FILTERFLAG_OOPLOGON) or whether headers and footers are extracted from the document (FILTERFLAG_HEADERFOOTERTAGS).


    Filter runs out of process by default. See The Filter Process Model for more information.

  2. Set the location of the Filter libraries by using the FilterDirectory property. These libraries are normally stored in the directory install\OS\bin, where install is the path name of the Filter installation directory and OS is the name of the operating system. For example:

    objFilter.FilterDirectory = filterDir;
  3. Set the input source as either a file or input stream by calling the SetInputSource method.

  4. Filter the file or stream by calling either the FilterTo or DoFilterChunk method. The FilterTo method extracts the data to a file or a stream. The DoFilterChunk method extracts one chunk of data from a file or a stream. It must be called repeatedly the until entire buffer is filtered.

    If filtering in file mode, use the following code:

         m_objFilter.filterTo(m_extractDir + filename + m_extension);

    If filtering in stream mode, use the following code:

         outf = new File(m_extractDir + filename + m_extension);
         fos = new FileOutputStream(outf);
  5. Terminate the filtering session and free allocated system resources by calling the ShutdownFilter() method. This must be called within a Finally block.