Class SelectionOutputTarget


  • public class SelectionOutputTarget
    extends OutputTarget

    An OutputTarget derivative that restricts the content added to the given StringBuffer to that within the starting and ending selection points specified in the constructor. This implementation would most commonly be paired with an interactive UI, where a user would be able to specify a range of content to be selected.

    Example:

     float x1 = 0, y1 = 450, x2 = 390, y2 = 72;
     
     Document pdf = PDF.open(pdfFile);
     StringBuffer sb = new StringBuffer();
     SelectionOutputTarget tgt = new SelectionOutputTarget(sb, x1, y1, x2, y2);
     
     pdf.getPage(0).pipe(tgt);
     p.pipe(tgt);
     pdf.close();
     
     String selectedText = sb.toString();
     
    Note that this OutputHandler retains OutputTarget's read-ordering and segmentation semantics, so the selection's start and end points are interpreted within that context; they are not the corners of a bounding or crop box as with RegionOutputTarget. That is, a start point that is within the first column of a page and an end point in the second column will result in all of the intervening text being extracted.

    Version:
    ©2004-2025 Snowtide
    • Constructor Detail

      • SelectionOutputTarget

        public SelectionOutputTarget​(StringBuffer sb,
                                     float x1,
                                     float y1,
                                     float x2,
                                     float y2)