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;
}
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();
}
Aggregations