Search in sources :

Example 1 with ILocationExtractionStrategy

use of com.itextpdf.kernel.pdf.canvas.parser.listener.ILocationExtractionStrategy in project i7j-pdfsweep by itext.

the class CompositeCleanupStrategy method getResultantLocations.

@Override
public Collection<IPdfTextLocation> getResultantLocations() {
    locations.clear();
    // build return value
    Set<IPdfTextLocation> retval = new LinkedHashSet<>();
    for (int i = 0; i < strategies.size(); i++) {
        ILocationExtractionStrategy s = strategies.get(i);
        Collection<IPdfTextLocation> rects = s.getResultantLocations();
        retval.addAll(rects);
        locations.put(i, new HashSet<>(rects));
    }
    List<IPdfTextLocation> rectangles = new ArrayList<>(retval);
    java.util.Collections.sort(rectangles, new Comparator<IPdfTextLocation>() {

        @Override
        public int compare(IPdfTextLocation l1, IPdfTextLocation l2) {
            Rectangle r1 = l1.getRectangle();
            Rectangle r2 = l2.getRectangle();
            if (r1.getY() == r2.getY()) {
                return r1.getX() == r2.getX() ? 0 : (r1.getX() < r2.getX() ? -1 : 1);
            } else {
                return r1.getY() < r2.getY() ? -1 : 1;
            }
        }
    });
    // return
    return rectangles;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ILocationExtractionStrategy(com.itextpdf.kernel.pdf.canvas.parser.listener.ILocationExtractionStrategy) IPdfTextLocation(com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation) ArrayList(java.util.ArrayList) Rectangle(com.itextpdf.kernel.geom.Rectangle)

Aggregations

Rectangle (com.itextpdf.kernel.geom.Rectangle)1 ILocationExtractionStrategy (com.itextpdf.kernel.pdf.canvas.parser.listener.ILocationExtractionStrategy)1 IPdfTextLocation (com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1