Search in sources :

Example 1 with PdfLinkAnnotation

use of com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation 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)

Example 2 with PdfLinkAnnotation

use of com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation in project i7js-highlevel by itext.

the class C06E09_Annotation method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    PdfAction js = PdfAction.createJavaScript("app.alert('Boo!');");
    PdfAnnotation la1 = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).setHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT).setAction(js).setBorderStyle(PdfAnnotation.STYLE_UNDERLINE);
    Link link1 = new Link("here", (PdfLinkAnnotation) la1);
    document.add(new Paragraph().add("Click ").add(link1).add(" if you want to be scared."));
    // here we need to add a page to the document beforehand, because we'll need to get its instance for destination creation
    pdf.addNewPage();
    PdfAnnotation la2 = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).setDestination(PdfExplicitDestination.createFit(pdf.getPage(2))).setHighlightMode(PdfAnnotation.HIGHLIGHT_PUSH).setBorderStyle(PdfAnnotation.STYLE_INSET);
    Link link2 = new Link("next page", (PdfLinkAnnotation) la2);
    document.add(new Paragraph().add("Go to the ").add(link2).add(" if you're too scared."));
    document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
    document.add(new Paragraph().add("There, there, everything is OK."));
    document.close();
}
Also used : PdfAction(com.itextpdf.kernel.pdf.action.PdfAction) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfLinkAnnotation(com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation) PdfAnnotation(com.itextpdf.kernel.pdf.annot.PdfAnnotation) Rectangle(com.itextpdf.kernel.geom.Rectangle) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Link(com.itextpdf.layout.element.Link) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

Rectangle (com.itextpdf.kernel.geom.Rectangle)2 PdfLinkAnnotation (com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation)2 PdfException (com.itextpdf.kernel.exceptions.PdfException)1 PdfArray (com.itextpdf.kernel.pdf.PdfArray)1 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)1 PdfName (com.itextpdf.kernel.pdf.PdfName)1 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)1 PdfAction (com.itextpdf.kernel.pdf.action.PdfAction)1 PdfAnnotation (com.itextpdf.kernel.pdf.annot.PdfAnnotation)1 PdfLineAnnotation (com.itextpdf.kernel.pdf.annot.PdfLineAnnotation)1 Document (com.itextpdf.layout.Document)1 AreaBreak (com.itextpdf.layout.element.AreaBreak)1 Link (com.itextpdf.layout.element.Link)1 Paragraph (com.itextpdf.layout.element.Paragraph)1 Logger (org.slf4j.Logger)1