Class PDFAnnotation

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPropertyChangeListener​(java.beans.PropertyChangeListener l)
      Add a PropertyChangeListener to this PDFAnnotation.
      AnnotationNote addReview​(java.lang.String name, java.lang.String status)
      Add a review to this annotation.
      protected java.lang.Object clone()  
      void flatten()
      Stamp the visible appearance of this annotation permanently onto its page, and remove the annotation from the page.
      PDFAction getAction​(Event event)
      Return the action assocaited with this event, as set by setAction(org.faceless.pdf2.Event, org.faceless.pdf2.PDFAction), or null if its unset.
      java.util.Collection<EmbeddedFile> getAssociatedFiles()
      Return the list of embedded files assocatiated with this PDFAnnotation.
      java.lang.String getAuthor()
      Return the author (or "Label") of the annotation if set, as set by setAuthor(java.lang.String) Note prior to version 2.3.7 this method existed, but only on certain subclasses.
      java.awt.Color getColor()
      Return the Color of the annotation as set by setColor(java.awt.Color), or null if not set.
      java.lang.String getContents()
      Return the value of the "Contents" property of this annotation, as set by setContents(java.lang.String).
      java.util.Calendar getCreationDate()
      Return the date when the annotation was first created if specified, or null otherwise.
      java.awt.color.ColorSpace getDefaultColorSpace​(int components)
      Return the ColorSpace used by this annotation to anchor device-dependent colors to a profile.
      PDFAnnotation getInReplyTo()
      Return the PDFAnnotation that this annotation is in reply to, or null if this annotation is not in reply to anything.
      java.util.Locale getLocale()
      Get the Locale on this annotation, as set by setLocale(java.util.Locale).
      java.io.Reader getMetaData()
      Return any XML metadata associated with this object.
      java.util.Calendar getModifyDate()
      Return the date when the annotation was last modified if specified, or null otherwise.
      int getOpacity()
      Return the opacity of this annotation, as set by setOpacity(int)
      OptionalContentDescriptor getOptionalContentDescriptor()
      Return the OptionalContentDescriptor previously set by setOptionalContentDescriptor(org.faceless.pdf2.OptionalContentDescriptor)
      PDFPage getPage()
      Return the page that this annotation is on, or null if it a new annotation which has not yet been placed on a page
      PDFAnnotation getPopup()
      Return the Popup annotation for this annotation.
      float[] getRectangle()
      Return the rectangle this annotation applies to on the page, or null if no rectangle applies for this type of annotation.
      java.util.List<PDFAnnotation> getReplies()
      Get an unmodifiable List of PDFAnnotation objects that are in reply to this Annotation.
      java.util.List<PDFAnnotation> getReviews()
      Get an unmodifiable List of PDFAnnotation objects that are reviews of this Annotation.
      java.lang.String getSubject()
      Get the subject of the annotation, as set by setSubject(java.lang.String)
      java.lang.String getType()
      Return the type of annotation.
      java.lang.String getUniqueID()
      Return the unique ID for this annotation, if set.
      java.lang.Object getUserData​(java.lang.String key)
      Return a property previously set on the PDF with the putUserData() method
      XMP getXMP()
      Return an XMP Metadata object representing any XML metadata associated with this object
      boolean hasAppearanceState​(java.lang.String state)
      Return true if this annotation has an appearance for the specified state.
      boolean isContentLocked()
      Returns whether the content of the annotation is locked
      boolean isPositionLocked()
      Returns whether the size and position of the annotation is locked
      boolean isPrintable()
      Returns whether the annotation is included when the document is printed (true) or not (false)
      boolean isReadOnly()
      Return whether the annotation to "read-only".
      boolean isVisible()
      Returns whether the annotation is visible on the screen (true) or not (false)
      void putLiteral​(java.lang.String key, java.lang.String tokens)
      Put a literal token sequnce.
      void putUserData​(java.lang.String key, java.lang.Object value)
      Set a custom property on the PDF.
      void rebuild()
      Rebuild the annotation's appearance.
      void removePropertyChangeListener​(java.beans.PropertyChangeListener l)
      Remove a previously added PropertyChangeListener from this PDFAnnotation.
      void setAction​(Event event, PDFAction action)
      Set an action to occur when the specified event happens to this annotation.
      void setAuthor​(java.lang.String label)
      Set the author of the annotation.
      void setColor​(java.awt.Color color)
      Set the Color of the annotation.
      void setContents​(java.lang.String contents)
      Set the "Contents" value of this annotation, which is required for "note" annotations and when making annotations accessible.
      void setCreationDate​(java.util.Calendar date)
      Set the date when the annotation was created.
      void setDefaultColorSpace​(int components, java.awt.color.ColorSpace cs)
      Set the ColorSpace to use to anchor device-dependent colors on this annotation, as described by getColorSpace(java.lang.String).
      void setInReplyTo​(PDFAnnotation annotation)
      Set which annotation this annotation is in reply to.
      void setLocale​(java.util.Locale locale)
      Set the Locale on this annotation.
      void setLocked​(boolean position, boolean content)
      Set the annotation to be "locked".
      void setMetaData​(java.lang.String metadata)
      Set the XML metadata associated with this object.
      void setModifyDate​(java.util.Calendar date)
      Set the date when the annotation is last modified.
      void setOpacity​(int opacity)
      Set the opacity of this annotation.
      void setOptionalContentDescriptor​(OptionalContentDescriptor descriptor)
      Set the optional content descriptor that this annotation belongs to.
      void setPage​(PDFPage page)
      Set the page for this annotation.
      void setPrintable​(boolean printable)
      Set whether the annotation is included when the document is printed.
      void setReadOnly​(boolean readonly)
      Set the annotation to "read-only", or not.
      void setRectangle​(float x1, float y1, float x2, float y2)
      Set the rectangle for the annotation - where it is on the page.
      void setSubject​(java.lang.String subject)
      Set the subject of the annotation.
      void setUniqueID​(java.lang.String id)
      Set the unique ID for this annotation.
      void setVisible​(boolean visible)
      Set whether the annotation is visible on screen.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getType

        public java.lang.String getType()
        Return the type of annotation. Could be one of "Text" (for AnnotationNotes), "Link", (for AnnotationLinks), "Stamp" (for AnnotationStamps), "Widget" (for WidgetAnnotations), "Highlight", "Underline", "Squiggly" or "StrikeOut" (for AnnotationMarkups), "FreeText" (for AnnotationTexts), "FileAttachment" (for AnnotationFiles) or "Line", "Square", "Circle", "Polygon", "Polyline", "Caret", "Ink", "Popup", "Sound", "Movie", "Screen", "PrinterMark" or "TrapNet", all of which only have only basic support with this API.
        Since:
        1.1.12
      • setRectangle

        public void setRectangle​(float x1,
                                 float y1,
                                 float x2,
                                 float y2)
        Set the rectangle for the annotation - where it is on the page. Every annotation must have a rectangle set - if it's not set when the document is written, it's forced to (0,0,0,0).
        • For AnnotationLink and AnnotationStamp annotations, this is the rectangle containing the hyperlink area or stamp.
        • For AnnotationNote annotations, whether this method adjusts the location of the icon or the popup window depends on whether the annotation is closed or open at the time of the call to this method. When closed, the icon is positioned at x1,y2

        Note that all co-ordinates are in absolute page co-ordinates. This means they are measured in points from the bottom-left hand corner of the page, regardless of any calls to PDFPage.rotate(float, float, double) or PDFPage.setUnits(float, int) that have been made. This restriction is part of the PDF specification.

        Parameters:
        x1 - the X co-ordinate of the bottom-left corner of the rectangle
        y1 - the Y co-ordinate of the bottom-left corner of the rectangle
        x2 - the X co-ordinate of the top-right corner of the rectangle
        y2 - the Y co-ordinate of the top-right corner of the rectangle
      • getPopup

        public PDFAnnotation getPopup()
        Return the Popup annotation for this annotation.
        Since:
        2.8
      • getRectangle

        public float[] getRectangle()
        Return the rectangle this annotation applies to on the page, or null if no rectangle applies for this type of annotation. See the setRectangle() method for a discussion on units.
        Returns:
        the rectangle for this annotation, in the form of an array (x1, y1, x2, y2)
        Since:
        1.1.12
        See Also:
        setRectangle(float, float, float, float)
      • hasAppearanceState

        public boolean hasAppearanceState​(java.lang.String state)
        Return true if this annotation has an appearance for the specified state.
        Parameters:
        state - the state to check - "N" for normal, "D" for down or "R" for rollover
        Since:
        2.10.3
      • getPage

        public PDFPage getPage()
        Return the page that this annotation is on, or null if it a new annotation which has not yet been placed on a page
        Since:
        1.1.23
      • setPage

        public void setPage​(PDFPage page)
        Set the page for this annotation. This is useful when moving annotations between documents or across pages - when simply adding a new annotation to a page, this method is identical to calling PDFPage.getAnnotations().add()
        Since:
        1.1.23
      • setVisible

        public void setVisible​(boolean visible)
        Set whether the annotation is visible on screen. By default, all new annotations are visible.
        Parameters:
        visible - whether the annotation should be displayed on the screen
        Since:
        1.1.23
      • setPrintable

        public void setPrintable​(boolean printable)
        Set whether the annotation is included when the document is printed. By default, all new annotations (except for hyperlinks) are printed.
        Parameters:
        printable - whether the annotation should be printed
        Since:
        1.1.23
      • setReadOnly

        public void setReadOnly​(boolean readonly)

        Set the annotation to "read-only", or not. Read-only annotations cannot be moved or deleted and do not respond to mouse clicks in Acrobat

        Additionally, using Acrobat there is no way to change this flag, so fields set to read-only using this method will basically stay that way unless edited with an API like this one. This makes this setting useful for placing "permanent" annotations on a page.

        Note this value is ignored for WidgetAnnotation objects - see the FormElement.setReadOnly(boolean) method instead

        Since:
        2.0
      • isVisible

        public boolean isVisible()
        Returns whether the annotation is visible on the screen (true) or not (false)
        Since:
        1.1.23
      • isPrintable

        public boolean isPrintable()
        Returns whether the annotation is included when the document is printed (true) or not (false)
        Since:
        1.1.23
      • setLocked

        public void setLocked​(boolean position,
                              boolean content)

        Set the annotation to be "locked". It's possible to lock the size and position of the annotation, the content, or both - although locking the content is only supported in Acrobat 8 or later

        Parameters:
        position - whether to lock the size/position of the annotation
        content - whether to lock the content of the annotation
        Since:
        2.11.4
      • isPositionLocked

        public boolean isPositionLocked()
        Returns whether the size and position of the annotation is locked
        Since:
        2.11.4
      • isContentLocked

        public boolean isContentLocked()
        Returns whether the content of the annotation is locked
        Since:
        2.11.4
      • setMetaData

        public void setMetaData​(java.lang.String metadata)
        Set the XML metadata associated with this object. Since 2.26 this method calls getXMP().read(new StringReader(xmldata == null ? "" : xmldata)). We strongly recommend using the getXMP() method and modifying the XMP directly rather than using this method.
        Parameters:
        metadata - the XML data to embed into the document, or null to clear any existing metadata. No validation is performed on this input.
        Since:
        2.11.5
        See Also:
        getXMP()
      • getMetaData

        public java.io.Reader getMetaData()
                                   throws java.io.IOException

        Return any XML metadata associated with this object.

        Since 2.26 this simply returns getXMP().isEmpty() ? null : new StringReader(getXMP().toString()). It is strongly recommended that any code migrates to using the getXMP() method.

        Since 2.24.3, the returned type is guaranteed to hava a toString() method that will return the Metadata as a String.

        Returns:
        a Reader containing the source of the XML or null if no metadata is available.
        Throws:
        java.io.IOException - if the metadata can't be extracted
        Since:
        2.11.5
      • getXMP

        public XMP getXMP()
        Return an XMP Metadata object representing any XML metadata associated with this object
        Returns:
        the XMP, which may be empty or invalid but will never be null
        Since:
        2.26
      • getModifyDate

        public java.util.Calendar getModifyDate()
        Return the date when the annotation was last modified if specified, or null otherwise.
        Since:
        2.0 - prior to that this method was called getLastModified
      • setModifyDate

        public void setModifyDate​(java.util.Calendar date)
        Set the date when the annotation is last modified. This is updated automatically when the annotation is modified, so there's no need to call this unless you need to set it to a specific value.
        Parameters:
        date - the Date to set the modification date to
        Since:
        2.7.1
      • getCreationDate

        public java.util.Calendar getCreationDate()
        Return the date when the annotation was first created if specified, or null otherwise.
        Since:
        2.0
      • setCreationDate

        public void setCreationDate​(java.util.Calendar date)
        Set the date when the annotation was created. This is set automatically when an annotation is created, so there's no need to call this method unless you need to set it to a specific value.
        Parameters:
        date - the Date to set the creation date to
        Since:
        2.7.1
      • setSubject

        public void setSubject​(java.lang.String subject)
        Set the subject of the annotation. This is an Acrobat 6.0 feature only, but will safely be ignored by earlier viewers. For some annotations (including AnnotationLink and WidgetAnnotation) this has no effect
        Parameters:
        subject - a brief summary of the contents of the annotation
        Since:
        2.0
      • setInReplyTo

        public void setInReplyTo​(PDFAnnotation annotation)
        Set which annotation this annotation is in reply to. This is an Acrobat 6 or later only feature, although it will safely be ignored by earlier viewers. The two annotations must be on the same page to be related like this - if they're not, this annotation will be moved to the page of it's reply. For some annotations (including AnnotationLink andWidgetAnnotation) this has no effect
        Parameters:
        annotation - the annotation this is in reply to, or null to remove the current value
        Since:
        2.0
      • getInReplyTo

        public PDFAnnotation getInReplyTo()
        Return the PDFAnnotation that this annotation is in reply to, or null if this annotation is not in reply to anything.
        Since:
        2.0
      • setUniqueID

        public void setUniqueID​(java.lang.String id)
        Set the unique ID for this annotation. See the getUniqueID() method for more information. Note that it is down to the user to ensure that the unique ID generated is actually unique. Since 2.3.7 all new annotations have a random unique ID generated when created.
        Parameters:
        id - the unique ID to assign to this annotation
        Since:
        2.0.8
      • getUniqueID

        public java.lang.String getUniqueID()
        Return the unique ID for this annotation, if set. This is the "NM" field, added as an optional attribute in Acrobat 5.0, and is usually in the form of a 15-30 random characters. If no unique ID is set, this method returns null.
        Since:
        2.0.8
      • setAuthor

        public void setAuthor​(java.lang.String label)
        Set the author of the annotation. This is also sometimes referred to as the Label. Note prior to version 2.3.7 this method existed, but only on certain subclasses. For some annotations (including AnnotationLink and WidgetAnnotation) this has no effect
        Since:
        2.3.7
      • getAuthor

        public java.lang.String getAuthor()
        Return the author (or "Label") of the annotation if set, as set by setAuthor(java.lang.String) Note prior to version 2.3.7 this method existed, but only on certain subclasses.
        Since:
        2.3.7
      • setContents

        public void setContents​(java.lang.String contents)
        Set the "Contents" value of this annotation, which is required for "note" annotations and when making annotations accessible. For note annotations, this is the contents of the pop-up window displayed when the annotation is open.
        Parameters:
        contents - the contents of the window - may contain newline and non-ASCII Unicode characters.
        Since:
        2.3.7
      • getContents

        public java.lang.String getContents()
        Return the value of the "Contents" property of this annotation, as set by setContents(java.lang.String).
        Since:
        2.3.7
      • setColor

        public void setColor​(java.awt.Color color)
        Set the Color of the annotation. This color will be used for the following purposes:
        • The background of the annotation's icon when closed, if applicable
        • The title bar of the annotation's pop-up window
        • The border of a link annotation
        Since:
        2.3.7
      • getColor

        public java.awt.Color getColor()
        Return the Color of the annotation as set by setColor(java.awt.Color), or null if not set.
        Since:
        2.3.7
      • setOpacity

        public void setOpacity​(int opacity)
        Set the opacity of this annotation. A value of 100 (the default) means the annotation is completely opaque, a value of 0 means completely invisible. For some annotations (including AnnotationLink and WidgetAnnotation) this has no effect Note this setting will be ignored by Acrobat 4.0 and earlier.
        Parameters:
        opacity - the opacity of the annotation from 0 to 100
        Since:
        2.3.7
      • rebuild

        public void rebuild()
        Rebuild the annotation's appearance. This will be done automatically when required, usually just before saving the PDF or rasterizing it to a bitmap. However this method can be called explicitly if necessary, usually to ensure the rebuild (which may fire a PropertyChangeEvent) is run on a specific thread.
        Since:
        2.11.26
      • getOpacity

        public int getOpacity()
        Return the opacity of this annotation, as set by setOpacity(int)
        Returns:
        the opacity of the annotation
        Since:
        2.3.7
      • addReview

        public AnnotationNote addReview​(java.lang.String name,
                                        java.lang.String status)
        Add a review to this annotation. See the getReviews() method for a more complete discussion of annotation reviews. This method is a convenient way of creating a new AnnotationNote, setting it's status and author, and marking it as in reply to this annotation. For some annotations (including AnnotationLink and WidgetAnnotation), this method will have no effect and will return null
        Parameters:
        name - the name of the person doing the review
        status - the status of the review - must be one of those listed for the AnnotationNote.setStatus(java.lang.String) method, or an IllegalArgumentException is thrown.
        Returns:
        the AnnotationNote that was created, or null if none was created
        Since:
        2.4
      • getReplies

        public java.util.List<PDFAnnotation> getReplies()

        Get an unmodifiable List of PDFAnnotation objects that are in reply to this Annotation.

        Since Acrobat 6.0 it has been possible to add "replies" to another annotation. These replies are actually PDFAnnotation objects - although the specification allows for any type of annotation to be used as a reply, in general only AnnotationNote objects are used. These annotations have the same physical location as the original one, but return a value from getInReplyTo(). Unlike those returned by getReviews(), they have a AnnotationNote.getStatus() equal to null.

        The list returned by this method is a convenient way of doing the following: Loop over all annotations on the same page as this one, and return any PDFAnnotation objects in reply to this one that have AnnotationNote.getStatus() equal to null.

        Note the returned list is unmodifiable - if you want to remove a reply, delete it from it's pages list of annotations.

        Returns:
        an unmodifiable List containing all the replies to this annotation
        Since:
        2.4
        See Also:
        getReplies(), setInReplyTo(org.faceless.pdf2.PDFAnnotation)
      • getReviews

        public java.util.List<PDFAnnotation> getReviews()

        Get an unmodifiable List of PDFAnnotation objects that are reviews of this Annotation.

        Since Acrobat 6.0 it has been possible to "review" another annotation by setting it's status to "Accepted", "Rejected", "Cancelled" or "Completed". It's also possible to "Mark" or "Unmark" an annotation (in Acrobat, this appears as a checkbox next to the annotation)

        These "reviews" are actually a collection of PDFAnnotation objects which are attached to the original annotation, very similar to the Replies as returned by getReplies(). The only different is that they have a "State" set, which you can see using the AnnotationNote.getStatus() method.

        The list returned from this method is a convenient way of doing the following: Loop over all annotations on the same page as this one, and return any PDFAnnotation objects in reply to this one, or one of it's other reviews, that have AnnotationNote.getStatus() set to a non-null value.

        Returns:
        an unmodifiable List containing all the Reviews of this annotation
        Since:
        2.4
        See Also:
        getReplies(), setInReplyTo(org.faceless.pdf2.PDFAnnotation), addReview(java.lang.String, java.lang.String), AnnotationNote.getStatus()
      • flatten

        public void flatten()

        Stamp the visible appearance of this annotation permanently onto its page, and remove the annotation from the page. The annotation object should be discarded afterwards.

        Note that this method removes this PDFAnnotation from the page list (and if this annotation is a Widget, from the FormElement.getAnnotations() FormElement Annotations list} as well), which could result in a ConcurrentModificationException if you were iterating over the page's annotations. To flatten all the annotations on a page we'd recommend something like this:

         List<PDFAnnotation> l = page.getAnnotations();
         while (!l.isEmpty()) {
           l.get(l.size() - 1).flatten();
         }
         
        Since:
        2.11.19
        See Also:
        FormElement.flatten(), Form.flatten()
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Set the Locale on this annotation. The locale property (really the Language property, but Locale is consistant with PDF#setLocale) on a PDFAnnotation is new in PDF 2.0
        Since:
        2.24.2
      • getLocale

        public java.util.Locale getLocale()
        Get the Locale on this annotation, as set by setLocale(java.util.Locale). The ability for an annotation to have a Locale is new in PDF 2.0
        Returns:
        the annotation locale, or PDF.LOCALEROOT if none is set
        Since:
        2.24.2
      • getAssociatedFiles

        public java.util.Collection<EmbeddedFile> getAssociatedFiles()
        Return the list of embedded files assocatiated with this PDFAnnotation. The list is live and can be edited. Note that prior to 2.26, this method returned a List rather than a Collection. It was changed to match the same methods on OutputProfile.getAssociatedFiles() and PDFPage.getAssociatedFiles(). The ability to associate files with a PDFAnnotation is new in PDF 2.0.
        Since:
        2.24.2
        See Also:
        AnnotationFile
      • putUserData

        public void putUserData​(java.lang.String key,
                                java.lang.Object value)
        Set a custom property on the PDF. The property will be saved with the file with the "BFOO_" prefix.
        Parameters:
        value - a CharSequence, Number, Date, Calendar, Boolean, byte[], or a List/Map of those values, or null to remove the property
        Since:
        2.24.2
      • getUserData

        public java.lang.Object getUserData​(java.lang.String key)
        Return a property previously set on the PDF with the putUserData() method
        Returns:
        a String, Boolean, Number, Calendar, byte[] or a Map/List of those values if found, or null if no such property exists.
        Since:
        2.24.2
      • getDefaultColorSpace

        public java.awt.color.ColorSpace getDefaultColorSpace​(int components)

        Return the ColorSpace used by this annotation to anchor device-dependent colors to a profile. For example, the ColorSpace returned by getDefaultColorSpace(3) is used by all "Device RGB" colors on the annotation, effectively turning them into calibrated colors.

        Annotations do not inherit any default ColorSpace set on the page.

        Parameters:
        components - identifies the Default ColorSpace we're requesting - valid values are 1 for Gray, 3 for RGB or 4 for CMYK.
        Returns:
        the Default ColorSpace requested, or null if none is set.
        Since:
        2.26.1
        See Also:
        PDFPage.getDefaultColorSpace(int)
      • setDefaultColorSpace

        public void setDefaultColorSpace​(int components,
                                         java.awt.color.ColorSpace cs)
        Set the ColorSpace to use to anchor device-dependent colors on this annotation, as described by getColorSpace(java.lang.String).
        Parameters:
        components - identifies the Default ColorSpace to set - valid values are 1 for Gray, 3 for RGB or 4 for CMYK.
        cs - the ColorSpace to set, which must be either null (to delete the existing value) or a ColorSpace of a type that matches the "components" parameter.
        Since:
        2.26.1
      • toString

        public java.lang.String toString()
      • putLiteral

        public void putLiteral​(java.lang.String key,
                               java.lang.String tokens)
        Put a literal token sequnce. For debugging
        Parameters:
        key - the key
        tokens - the token sequence, eg "true" or "/foo" or "[/Foo/Bar]". No refs, just direct objects.
      • clone

        protected java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object