com.groupdocs.parser

Interfaces

Classes

Exceptions

com.groupdocs.parser

Class EpubFormattedTextExtractor

  • All Implemented Interfaces:
    IHighlightExtractor, ITextExtractorWithFormatter, AutoCloseable


    public final class EpubFormattedTextExtractor
    extends EpubTextExtractorBase
    implements IHighlightExtractor, ITextExtractorWithFormatter

    Provides the formatted text extractor for EPUB documents.

    Extracts a line of characters from a document:

     // Create a text extractor for EPUB documents
     TextExtractor extractor = new EpubFormattedTextExtractor(stream);
     // Extract a line of the text
     String line = extractor.extractLine();
     // If the line is null, then the end of the file is reached
     while (line != null) {
         // Print a line to the console
         System.out.println(line);
         // Extract another line
         line = extractor.extractLine();
     }
      

    Extracts all characters from a document:

     // Create a text extractor for EPUB documents
     TextExtractor extractor = new EpubFormattedTextExtractor(stream);
     // Extract a text
     System.out.println(extractor.extractAll());
      

    For setting a formatter DocumentFormatter property is used.

     // Create a formatted text extractor for text documents
     EpubFormattedTextExtractor extractor = new EpubFormattedTextExtractor(stream);
     // Set a markdown formatter for formatting
     extractor.setDocumentFormatter(new MarkdownDocumentFormatter()); // all the text will be formatted as Markdown
      

    By default a text is formatted as a plain text by Formatters.Plain.PlainDocumentFormatter.

    • Constructor Detail

      • EpubFormattedTextExtractor

        public EpubFormattedTextExtractor(String fileName)

        Initializes a new instance of the EpubFormattedTextExtractor class.

        Parameters:
        fileName - The path to the file.
      • EpubFormattedTextExtractor

        public EpubFormattedTextExtractor(InputStream stream)

        Initializes a new instance of the EpubFormattedTextExtractor class.

        Parameters:
        stream - The stream of the document.
    • Method Detail

      • getDocumentFormatter

        public DocumentFormatter getDocumentFormatter()

        Gets a DocumentFormatter.

        Specified by:
        getDocumentFormatter in interface ITextExtractorWithFormatter
        Returns:
        An instance of the DocumentFormatter. The default is PlainDocumentFormatter.


        By default the value is an instance of PlainDocumentFormatter class. You can set any other formatter or null, if you want to use default formatter.

      • setDocumentFormatter

        public void setDocumentFormatter(DocumentFormatter value)

        Sets a DocumentFormatter.

        Specified by:
        setDocumentFormatter in interface ITextExtractorWithFormatter
        Parameters:
        value - An instance of the DocumentFormatter. The default is PlainDocumentFormatter.


        By default the value is an instance of PlainDocumentFormatter class. You can set any other formatter or null, if you want to use default formatter.

      • extractHighlights

        public List<String> extractHighlights(HighlightOptions... highlightOptions)

        Extracts highlights.

        Specified by:
        extractHighlights in interface IHighlightExtractor
        Parameters:
        highlightOptions - A collection of HighlightOptions.


        Supports only the extraction with Mode = FixedWidth.

        Returns:
        A collection of strings that represent highlights. If no highlight is found, a collection is empty.
        Throws:
        UnsupportedOperationException - Mode is not FixedWith.
      • reset

        public void reset()

        Resets the current document.


        Resets the cursor's position. ExtractLine method will return the first line of the document.

        Overrides:
        reset in class EpubTextExtractorBase
      • extractText

        protected String extractText()

        Extracts all characters from the current position to the end of the text extractor and returns them as one string.

        Overrides:
        extractText in class TextExtractor
        Returns:
        A string that contains all characters from the current position to the end of the text extractor.
      • extractTextLine

        protected String extractTextLine()

        Extracts a line of characters from the text extractor and returns the data as a string.

        Overrides:
        extractTextLine in class TextExtractor
        Returns:
        The next line from the extractor, or null if all characters have been extracted.
      • extractItem

        protected String extractItem(String path)

        Extracts a text from the document's item.

        Specified by:
        extractItem in class EpubTextExtractorBase
        Parameters:
        path - A path to the document's item.
        Returns:
        A string that contains all characters from the document's item.