Refine search
/** * Check if the Dest element is authorized according to the A entry * * @return if the Dest element is authorized according to the A entry. */ protected boolean checkDest() { try { if (this.pdLink.getDestination() != null && this.pdLink.getAction() != null) { ctx.addValidationError(new ValidationError(ERROR_ANNOT_FORBIDDEN_DEST, "Dest can't be used due to A element")); return false; } COSDictionary dict = pdLink.getCOSObject(); COSBase dest = dict.getDictionaryObject(COSName.DEST); if (dest != null) { ContextHelper.validateElement(ctx, dest, DESTINATION_PROCESS); } } catch (IOException e) { ctx.addValidationError(new ValidationError(ERROR_ANNOT_INVALID_DEST, e.getMessage(), e)); return false; } return true; } }
public LinkAnnotationValidator(PreflightContext ctx, COSDictionary annotDictionary) { super(ctx, annotDictionary); this.pdLink = new PDAnnotationLink(annotDictionary); this.pdAnnot = this.pdLink; }
private void processAnnotations(PDPage imported) throws IOException { List<PDAnnotation> annotations = imported.getAnnotations(); for (PDAnnotation annotation : annotations) { if (annotation instanceof PDAnnotationLink) { PDAnnotationLink link = (PDAnnotationLink)annotation; PDDestination destination = link.getDestination(); if (destination == null && link.getAction() != null) { PDAction action = link.getAction(); if (action instanceof PDActionGoTo) { destination = ((PDActionGoTo)action).getDestination(); } } if (destination instanceof PDPageDestination) { // TODO preserve links to pages within the splitted result ((PDPageDestination) destination).setPage(null); } } // TODO preserve links to pages within the splitted result annotation.setPage(null); } } /**
/** * Get the destination to be displayed when the annotation is activated. Either this or the * action entry should be set, but not both. * * @return The destination for this annotation. * * @throws IOException If there is an error creating the destination. */ public PDDestination getDestination() throws IOException { COSBase base = getCOSObject().getDictionaryObject(COSName.DEST); return PDDestination.create(base); }
/** * The new destination value. Either this or the action entry should be set, but not both. * * @param dest The updated destination. */ public void setDestination(PDDestination dest) { getCOSObject().setItem(COSName.DEST, dest); }
PDAnnotationLink txtLink = new PDAnnotationLink(); txtLink.setBorderStyle(borderULine); position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 1.5f * INCH); txtLink.setRectangle(position); txtLink.setAction(action); annotations.add(txtLink); PDAnnotationLink pageLink = new PDAnnotationLink(); pageLink.setBorderStyle(borderULine); position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 2 * INCH); pageLink.setRectangle(position); pageLink.setAction(actionGoto); annotations.add(pageLink); polygon.getCOSObject().setName(COSName.SUBTYPE, PDAnnotationMarkup.SUB_TYPE_POLYGON); position = new PDRectangle(); position.setLowerLeftX(pw - INCH); polygon.setRectangle(position);
PDAnnotationLink txtLink = new PDAnnotationLink(); txtLink.setBorderStyle(borderULine); position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 1.5f * INCH); txtLink.setRectangle(position); txtLink.setAction(action); annotations.add(txtLink); PDAnnotationLink pageLink = new PDAnnotationLink(); pageLink.setBorderStyle(borderULine); position.setUpperRightX(INCH + textWidth); position.setUpperRightY(ph - 2 * INCH); pageLink.setRectangle(position); pageLink.setAction(actionGoto); annotations.add(pageLink);
String subtype = annotDic.getNameAsString(COSName.SUBTYPE); if (PDAnnotationFileAttachment.SUB_TYPE.equals(subtype)) annot = new PDAnnotationLink(annotDic);
PDAction action = link.getAction(); if( action instanceof PDActionURI )
PDAnnotationLink link = new PDAnnotationLink(); PDActionNamed action = new PDActionNamed (); action.setN("GoBack"); // this is one of Acrobat's default named action link.setAction(action);
/** * Set the highlight mode for when the mouse is depressed. See the HIGHLIGHT_MODE_XXX constants. * * @return The string representation of the highlight mode. */ public String getHighlightMode() { return getCOSObject().getNameAsString(COSName.H, HIGHLIGHT_MODE_INVERT); }
float textWidth = font.getStringWidth(text) / 1000.0 * 12; PDAnnotationLink link = new PDAnnotationLink(); PDGamma colourBlue = new PDGamma(); colourBlue.setB(1); link.setColour(colourBlue); action.setURI(currFol.getName() + "/" + currDoc.getName()); link.setAction(action); position.setUpperRightX(x + textWidth); position.setUpperRightY(y + 12); link.setRectangle(position);
private PDRectangle addAnnotationLinkRectangle(final float x, final float y, final float width, final float height, final String linkURL) throws IOException { final float startingY = checkYAndSwitchPage(y, height); final PDAnnotationLink txtLink = new PDAnnotationLink(); final PDRectangle position = new PDRectangle(); position.setLowerLeftX(x); position.setLowerLeftY(startingY); position.setUpperRightX(x + width); position.setUpperRightY(startingY + height); txtLink.setRectangle(position); final PDActionURI action = new PDActionURI(); action.setURI(linkURL); txtLink.setAction(action); currentPage.getAnnotations().add(txtLink); return new PDRectangle(x, startingY, width, height); }
void sanitizeLinkAnnotation(PDAnnotationLink annotationLink) { if (annotationLink.getAction() == null) { return; } LOGGER.debug("Found&removed annotation link - action, was {}", annotationLink.getAction()); pdfBleachSession.recordJavascriptThreat("Annotation", "External link"); annotationLink.setAction(null); }
/** * Constructor. */ public PDAnnotationLink() { getCOSObject().setName(COSName.SUBTYPE, SUB_TYPE); }
action.setDestination(dest); PDAnnotationLink link = new PDAnnotationLink(); link.setAction(action); link.setDestination(dest);
if (annotation.getRectangle() == null) try (PDAppearanceContentStream contentStream = getNormalAppearanceAsContentStream()) PDColor color = annotation.getColor(); if (color == null) contentStream.setBorderLine(lineWidth, annotation.getBorderStyle(), annotation.getBorder()); float[] pathsArray = annotation.getQuadPoints(); PDRectangle rect = annotation.getRectangle(); for (int i = 0; i < pathsArray.length / 2; ++i) while (of + 7 < pathsArray.length) if (annotation.getBorderStyle() != null && annotation.getBorderStyle().getStyle().equals(PDBorderStyleDictionary.STYLE_UNDERLINE))
@SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean placeAnnotation(AffineTransform transform, Shape linkShape, Rectangle2D targetArea, PDAnnotationLink annot) { annot.setRectangle(new PDRectangle((float) targetArea.getMinX(), (float) targetArea.getMinY(), (float) targetArea.getWidth(), (float) targetArea.getHeight())); if (linkShape != null) { float[] quadPoints = mapShapeToQuadPoints(transform, linkShape, targetArea); /* * Is this not an area shape? Then we can not setup quads - ignore this shape. */ if (quadPoints.length == 0) return false; annot.setQuadPoints(quadPoints); } return true; }
private void drawAnnotationLinkBorder(PDAnnotationLink link) throws IOException { AnnotationBorder ab = getAnnotationBorder(link, link.getBorderStyle()); if (ab.width == 0 || ab.color.getComponents().length == 0) { return; } PDRectangle rectangle = link.getRectangle(); Stroke oldStroke = graphics.getStroke(); graphics.setPaint(getPaint(ab.color)); BasicStroke stroke = new BasicStroke(ab.width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, ab.dashArray, 0); graphics.setStroke(stroke); graphics.setClip(null); if (ab.underline) { graphics.drawLine((int) rectangle.getLowerLeftX(), (int) rectangle.getLowerLeftY(), (int) (rectangle.getLowerLeftX() + rectangle.getWidth()), (int) rectangle.getLowerLeftY()); } else { graphics.drawRect((int) rectangle.getLowerLeftX(), (int) rectangle.getLowerLeftY(), (int) rectangle.getWidth(), (int) rectangle.getHeight()); } graphics.setStroke(oldStroke); }
private void addLinkToPage(PDPage page, PDAnnotationLink annot) { PDBorderStyleDictionary styleDict = new PDBorderStyleDictionary(); styleDict.setWidth(0); styleDict.setStyle(PDBorderStyleDictionary.STYLE_SOLID); annot.setBorderStyle(styleDict); try { List<PDAnnotation> annots = page.getAnnotations(); if (annots == null) { annots = new ArrayList<PDAnnotation>(); page.setAnnotations(annots); } annots.add(annot); } catch (IOException e) { throw new PdfContentStreamAdapter.PdfException("processLink", e); } }