/** * Get the annotations appearance dictionary. * * <p> * This will get the annotations appearance dictionary. If this is not * existent an empty appearance dictionary will be created. * * @return the annotations appearance dictionary */ PDAppearanceDictionary getAppearance() { PDAppearanceDictionary appearanceDictionary = annotation.getAppearance(); if (appearanceDictionary == null) { appearanceDictionary = new PDAppearanceDictionary(); annotation.setAppearance(appearanceDictionary); } return appearanceDictionary; }
/** * This will set the annotations appearance state name. * * @param as The name of the appearance stream. */ public void setAppearanceState(String as) { getCOSObject().setName(COSName.AS, as); }
/** * Checks if flags of the annotation are authorized. * <UL> * <li>Print flag must be 1 * <li>NoView flag must be 0 * <li>Hidden flag must be 0 * <li>Invisible flag must be 0 * </UL> * If one of these flags is invalid, the errors list is updated with the ERROR_ANNOT_FORBIDDEN_FLAG ValidationError * code. * * @return false if a flag is invalid, true otherwise. */ protected boolean checkFlags() { boolean result = this.pdAnnot.isPrinted(); result = result && !this.pdAnnot.isHidden(); result = result && !this.pdAnnot.isInvisible(); result = result && !this.pdAnnot.isNoView(); if (!result) { ctx.addValidationError(new ValidationError(ERROR_ANNOT_FORBIDDEN_FLAG, "Flags of " + pdAnnot.getSubtype() + " annotation are invalid")); } return result; }
@Override Object[][] getFlagBits() { PDAnnotation annotation = new PDAnnotation(annotDictionary) { }; return new Object[][]{ new Object[]{1, "Invisible", annotation.isInvisible()}, new Object[]{2, "Hidden", annotation.isHidden()}, new Object[]{3, "Print", annotation.isPrinted()}, new Object[]{4, "NoZoom", annotation.isNoZoom()}, new Object[]{5, "NoRotate", annotation.isNoRotate()}, new Object[]{6, "NoView", annotation.isNoView()}, new Object[]{7, "ReadOnly", annotation.isReadOnly()}, new Object[]{8, "Locked", annotation.isLocked()}, new Object[]{9, "ToggleNoView", annotation.isToggleNoView()}, new Object[]{10, "LockedContents", annotation.isLocked()} }; } }
if (deviceType == GraphicsDevice.TYPE_PRINTER && !annotation.isPrinted()) if (deviceType == GraphicsDevice.TYPE_RASTER_SCREEN && annotation.isNoView()) if (annotation.isHidden()) if (annotation.getAppearance() == null) if (annotation instanceof PDAnnotationMarkup && annotation.getSubtype().equals(PDAnnotationMarkup.SUB_TYPE_INK))
if (widgetsForPageMap != null && widgetsForPageMap.get(annotation.getCOSObject()) == null) else if (!annotation.isInvisible() && !annotation.isHidden() && annotation.getNormalAppearanceStream() != null) PDAppearanceStream appearanceStream = annotation.getNormalAppearanceStream(); transformationMatrix.translate(annotation.getRectangle().getLowerLeftX(), annotation.getRectangle().getLowerLeftY()); transformed = true; PDRectangle fieldRect = annotation.getRectangle();
if (deviceType == GraphicsDevice.TYPE_PRINTER && !annotation.isPrinted()) if (deviceType == GraphicsDevice.TYPE_RASTER_SCREEN && annotation.isNoView()) if (annotation.isHidden()) PDPropertyList propertyList = annotation.getOptionalContent(); if (propertyList instanceof PDOptionalContentGroup) if (annotation.getAppearance() == null) annotation.constructAppearances(); if (annotation.isNoRotate() && getCurrentPage().getRotation() != 0) PDRectangle rect = annotation.getRectangle(); AffineTransform savedTransform = graphics.getTransform();
private static String getN_type(PDAnnotation annot) { PDAppearanceDictionary appearanceDictionary = annot.getAppearance(); if (appearanceDictionary != null) { PDAppearanceEntry normalAppearance = appearanceDictionary.getNormalAppearance(); if (normalAppearance == null) { return null; } else if (normalAppearance.isSubDictionary()) { return DICT; } else { return STREAM; } } return null; }
/** * Checks if all mandatory fields of an annotation are present. If some fields are missing, the method returns false * and the errors list is updated. * * @return true if validation succeed, false otherwise. */ protected boolean checkMandatoryFields() { boolean subtype = this.annotDictionary.containsKey(COSName.SUBTYPE); boolean rect = this.annotDictionary.containsKey(COSName.RECT); boolean result = (subtype && rect && checkSpecificMandatoryFields()); if (!result) { ctx.addValidationError(new ValidationError(ERROR_ANNOT_MISSING_FIELDS, "A mandatory field for the " + this.pdAnnot.getSubtype() + " annotation is missing")); } return result; }
public PBoxPDAnnot(PDAnnotation annot, PDResources pageResources, PDDocument document, PDFAFlavour flavour) { super(annot, ANNOTATION_TYPE); this.pageResources = pageResources; this.subtype = annot.getSubtype(); this.ap = getAP(annot); COSDictionary annotDict = annot.getCOSObject(); this.isFKeyPresent = annotDict.containsKey(COSName.F); this.annotationFlag = annot.getAnnotationFlags(); this.ca = PBoxPDAnnot.getCA(annot); this.nType = getN_type(annot); this.ft = PBoxPDAnnot.getFT(annot); this.width = PBoxPDAnnot.getWidth(annot); this.height = PBoxPDAnnot.getHeight(annot); this.document = document; this.flavour = flavour; }
PDColor getColor() { return annotation.getColor(); }
protected boolean checkFlags() { // call common flags settings boolean result = super.checkFlags(); /* * For Text Annotation, this two flags should be set to avoid potential ambiguity between the annotation * dictionary and the reader behavior. */ result = result && this.pdAnnot.isNoRotate(); result = result && this.pdAnnot.isNoZoom(); if (!result) { ctx.addValidationError(new ValidationError(ERROR_ANNOT_NOT_RECOMMENDED_FLAG)); } return result; } }
/** * Returns the appearance stream for this annotation, if any. The annotation state is taken into account, if * present. */ public PDAppearanceStream getNormalAppearanceStream() { PDAppearanceDictionary appearanceDict = getAppearance(); if (appearanceDict == null) { return null; } PDAppearanceEntry normalAppearance = appearanceDict.getNormalAppearance(); if (normalAppearance == null) { return null; } if (normalAppearance.isSubDictionary()) { COSName state = getAppearanceState(); return normalAppearance.getSubDictionary().get(state); } else { return normalAppearance.getAppearanceStream(); } }
PDRectangle getRectangle() { return annotation.getRectangle(); }
PDRectangle rect = annot.getRectangle(); String appearanceName = annot.getAppearanceStream(); PDAppearanceDictionary appearDictionary = annot.getAppearance(); if( appearDictionary != null )
@Override public boolean isInvisible() { return annot != null && annot.isInvisible(); }
@Override public boolean isNoView() { return annot != null && annot.isNoView(); }
@Override public boolean isPrinted() { return annot != null && annot.isPrinted(); }
@Override public boolean isHidden() { return annot != null && annot.isHidden(); }