use of com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation 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;
}
use of com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation in project i7j-pdfsweep by itext.
the class PdfAutoSweepTools method getPdfCleanUpLocations.
/**
* Get all {@link PdfCleanUpLocation} objects from a given {@link PdfPage}.
*
* @param page the {@link PdfPage} to be processed
*
* @return a List of {@link PdfCleanUpLocation} objects
*/
public List<PdfCleanUpLocation> getPdfCleanUpLocations(PdfPage page) {
// get document
PdfDocument doc = page.getDocument();
// create parser
PdfDocumentContentParser parser = new PdfDocumentContentParser(doc);
// get page number
int pageNr = doc.getPageNumber(page);
// process document
List<PdfCleanUpLocation> toClean = new ArrayList<>();
parser.processContent(pageNr, strategy);
for (IPdfTextLocation rect : strategy.getResultantLocations()) {
if (rect != null) {
toClean.add(new PdfCleanUpLocation(pageNr, rect.getRectangle(), strategy.getRedactionColor(rect)));
}
}
// reset strategy for next iteration
resetStrategy();
// return
return toClean;
}
use of com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation in project i7j-pdfsweep by itext.
the class PdfAutoSweepTools method getPdfCleanUpLocations.
/**
* Get all {@link PdfCleanUpLocation} objects from a given {@link PdfDocument}.
*
* @param doc the {@link PdfDocument} to be processed
*
* @return a List of {@link PdfCleanUpLocation} objects
*/
public List<PdfCleanUpLocation> getPdfCleanUpLocations(PdfDocument doc) {
PdfDocumentContentParser parser = new PdfDocumentContentParser(doc);
List<PdfCleanUpLocation> toClean = new ArrayList<>();
for (int pageNr = 1; pageNr <= doc.getNumberOfPages(); pageNr++) {
parser.processContent(pageNr, strategy);
for (IPdfTextLocation rect : strategy.getResultantLocations()) {
if (rect != null) {
toClean.add(new PdfCleanUpLocation(pageNr, rect.getRectangle(), strategy.getRedactionColor(rect)));
}
}
resetStrategy();
}
java.util.Collections.sort(toClean, new Comparator<PdfCleanUpLocation>() {
@Override
public int compare(PdfCleanUpLocation o1, PdfCleanUpLocation o2) {
if (o1.getPage() != o2.getPage()) {
return o1.getPage() < o2.getPage() ? -1 : 1;
}
Rectangle r1 = o1.getRegion();
Rectangle r2 = o2.getRegion();
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 toClean;
}
Aggregations