Class TextTool

  • All Implemented Interfaces:
    PropertyChangeListener, EventListener, DocumentPanelListener, PagePanelInteractionListener, PagePanelListener

    public class TextTool
    extends ToggleViewerWidget
    implements DocumentPanelListener, PagePanelInteractionListener, PagePanelListener, PropertyChangeListener

    This widget allows text to be selected from the DocumentViewport. By default it uses a translucent yellow highlight, but this can be set using the setHighlightType() method or the matching initialization parameters. When the text is highlighted, right-clicking on the page will bring up a list of any TextSelectionAction features specified in the viewer.

    The TextTool object selects text in a document-wide manner, not just from the currently visible pages (which was the behaviour prior to 2.11.7). This means operations like selectAll() or select(Pattern) require all the text in the PDF to be extracted, which can cause these two operations to take some time to complete. One solution is to add the BackgroundTextExtractor feature, which will automatically begin the text extaction when a PDF is loaded.

    The TextHighlighter class performs a similar job, except no mouse selection or no copying to the clipboard is possible. These differences mean if you simply want to highlight text matching a pattern, this class will have to extract text from the entire PDF first, whereas that class will do it on a page by page basis.

    The following initialization parameters can be specified to configure this feature.
    highlightColorA 32-bit color value, eg 0x80FF0000 (for translucent red)
    highlightTypeOne of block, underline, outline, doubleunderline, strikeout or doublestrikeout
    highlightMarginA floating point value >= 0
    draggabletrue or false, for setDraggable(boolean)
    selectPatternA java.util.regex.Pattern to be searched for automatically when a PDF is loaded
    selectTextToolOnTextSelectionif specified, toggle text selection mode in the viewer when text is selected by other means (e.g. clicking a search result)
    selectionOrderdisplay or natural, to set the order text is selected in when dragging the mouse. Defaults to "natural".
    The name of this feature is TextTool

    This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.

    See Also: