Search in sources :

Example 1 with PdfLineAnnotation

use of com.itextpdf.kernel.pdf.annot.PdfLineAnnotation in project i7j-pdfsweep by itext.

the class PdfCleanUpProcessor method annotationIsToBeRedacted.

private boolean annotationIsToBeRedacted(PdfAnnotation annotation, Rectangle redactRegion) {
    // TODO(DEVSIX-1605,DEVSIX-1606,DEVSIX-1607,DEVSIX-1608,DEVSIX-1609)
    removeAnnotIfPartOverlap = true;
    PdfName annotationType = annotation.getPdfObject().getAsName(PdfName.Subtype);
    if (annotationType.equals(PdfName.Watermark)) {
        // TODO /FixedPrint entry effect is not fully investigated: DEVSIX-2471
        Logger logger = LoggerFactory.getLogger(PdfCleanUpProcessor.class);
        logger.warn(CleanUpLogMessageConstant.REDACTION_OF_ANNOTATION_TYPE_WATERMARK_IS_NOT_SUPPORTED);
    }
    PdfArray rectAsArray = annotation.getRectangle();
    Rectangle rect = null;
    if (rectAsArray != null) {
        rect = rectAsArray.toRectangle();
    }
    boolean annotationIsToBeRedacted = processAnnotationRectangle(redactRegion, rect);
    // Special processing for some types of annotations.
    if (PdfName.Link.equals(annotationType)) {
        PdfArray quadPoints = ((PdfLinkAnnotation) annotation).getQuadPoints();
        if (quadPointsForLinkAnnotationAreValid(rect, quadPoints)) {
            annotationIsToBeRedacted = processAnnotationQuadPoints(redactRegion, quadPoints);
        }
    } else if (annotationType.equals(PdfName.Highlight) || annotationType.equals(PdfName.Underline) || annotationType.equals(PdfName.Squiggly) || annotationType.equals(PdfName.StrikeOut)) {
        PdfArray quadPoints = ((PdfTextMarkupAnnotation) annotation).getQuadPoints();
        // The annotation dictionary’s AP entry, if present, shall take precedence over QuadPoints.
        if (quadPoints != null && annotation.getAppearanceDictionary() == null) {
            try {
                annotationIsToBeRedacted = processAnnotationQuadPoints(redactRegion, quadPoints);
            } catch (PdfException ignored) {
            // if quad points array cannot be processed, simply ignore it
            }
        }
    } else if (annotationType.equals(PdfName.Line)) {
        PdfArray line = ((PdfLineAnnotation) annotation).getLine();
        if (line != null) {
            Rectangle drawnLineRectangle = line.toRectangle();
            // Line annotation might contain line leaders, so let's double check overlapping with /Rect area, for simplicity.
            // TODO DEVSIX-1607
            annotationIsToBeRedacted = annotationIsToBeRedacted || processAnnotationRectangle(redactRegion, drawnLineRectangle);
        }
    }
    return annotationIsToBeRedacted;
}
Also used : PdfArray(com.itextpdf.kernel.pdf.PdfArray) PdfException(com.itextpdf.kernel.exceptions.PdfException) PdfName(com.itextpdf.kernel.pdf.PdfName) PdfLinkAnnotation(com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation) PdfLineAnnotation(com.itextpdf.kernel.pdf.annot.PdfLineAnnotation) Rectangle(com.itextpdf.kernel.geom.Rectangle) Logger(org.slf4j.Logger)

Aggregations

PdfException (com.itextpdf.kernel.exceptions.PdfException)1 Rectangle (com.itextpdf.kernel.geom.Rectangle)1 PdfArray (com.itextpdf.kernel.pdf.PdfArray)1 PdfName (com.itextpdf.kernel.pdf.PdfName)1 PdfLineAnnotation (com.itextpdf.kernel.pdf.annot.PdfLineAnnotation)1 PdfLinkAnnotation (com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation)1 Logger (org.slf4j.Logger)1