Highlighting PDF Text in Viewer
JPedal allows PDF text to be highlighted on screen, for example to show words found on a wordsearch
JPedal will highlight the area defined by the font bounding box, which provides the best general fit for all fonts. JPedal will remove small gaps between words, but not large ones as this can cause issues on some PDF files.
If PDF text is highlighted, a background is drawn behind the PDF text and the PDF text is rendered in inverse video. The color is theTEXT_HIGHLIGHT_COLOUR which can be set using Custom JPedal settings.
The user tells JPedal to highlight PDF text in a single or many rectangular area and any PDF text fully enclosed is highlighted. There is a single method in PdfDecoder to set PDF highlights addHighlights(java.awt.Rectangle highlights, boolean areaSelect). The boolean flag will determine how the PDF highlights are handled. Either each area is a rectangle to highlight all PDF text within the area or as two points to calculate all lines within and partial lines at the top and bottom of the area.
Areas can be selectively removed with the methods removeFoundTextArea(java.awt.Rectangle) or removeFoundTextAreas(java.awt.Rectangle). There is also a method called clearHighlights() which will remove all displayed PDF highlights.
Please note: PDF co-ordinates, which treat the bottom left of the page at origin (0,0) are used and not Java co-ordinates (where the origin is top left). You can easily see PDF co-ordinates displayed in the Java PDF viewer.
The Java PDF viewers include a PDF search facility which uses PDF text highlighting. So there is a documented example in org.jpedal.examples.viewer.gui.swing.SearchWindow, showing how to use the Java code.