use of com.itextpdf.pdfcleanup.PdfCleanUpLocation 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.pdfcleanup.PdfCleanUpLocation 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;
}
use of com.itextpdf.pdfcleanup.PdfCleanUpLocation in project i7j-pdfsweep by itext.
the class PdfAutoSweepTools method tentativeCleanUp.
/**
* Perform tentative cleanup of areas of interest on a given {@link PdfPage}
* This method will add all redaction annotations to the given page, allowing
* the end-user to choose which redactions to keep or delete.
*
* @param pdfPage the page to clean up
*/
public void tentativeCleanUp(PdfPage pdfPage) {
List<PdfCleanUpLocation> cleanUpLocations = getPdfCleanUpLocations(pdfPage);
for (PdfCleanUpLocation loc : cleanUpLocations) {
PdfString title = new PdfString("Annotation:" + annotationNumber);
annotationNumber++;
float[] color = loc.getCleanUpColor().getColorValue();
// convert to annotation
PdfAnnotation redact = new PdfRedactAnnotation(loc.getRegion()).setDefaultAppearance(new PdfString("Helvetica 12 Tf 0 g")).setTitle(title).put(PdfName.Subj, PdfName.Redact).put(PdfName.IC, new PdfArray(new float[] { 0f, 0f, 0f })).put(PdfName.OC, new PdfArray(color));
pdfPage.addAnnotation(redact);
}
}
use of com.itextpdf.pdfcleanup.PdfCleanUpLocation in project i7j-pdfsweep by itext.
the class CleanupImageWithColorSpaceTest method cleanUpTestColorSpaceJpegBaselineEncoded.
@Test
public void cleanUpTestColorSpaceJpegBaselineEncoded() throws Exception {
// cleanup jpeg image with baseline encoded data
String input = inputPath + "imgSeparationCsJpegBaselineEncoded.pdf";
String output = outputPath + "imgSeparationCsJpegBaselineEncoded.pdf";
String cmp = inputPath + "cmp_imgSeparationCsJpegBaselineEncoded.pdf";
cleanUp(input, output, Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(60f, 600f, 100f, 50f), ColorConstants.GREEN)));
compareByContent(cmp, output, outputPath, "11");
}
use of com.itextpdf.pdfcleanup.PdfCleanUpLocation in project i7j-pdfsweep by itext.
the class CleanupImageWithColorSpaceTest method cleanUpTestColorSpace.
@Test
public void cleanUpTestColorSpace() throws Exception {
String input = inputPath + "imgSeparationCs.pdf";
String output = outputPath + "imgSeparationCs.pdf";
String cmp = inputPath + "cmp_imgSeparationCs.pdf";
cleanUp(input, output, Arrays.asList(new PdfCleanUpLocation(1, new Rectangle(60f, 780f, 60f, 45f), ColorConstants.GREEN)));
compareByContent(cmp, output, outputPath, "9");
}
Aggregations