Class AnnotationFile

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class AnnotationFile
    extends PDFAnnotation

    A subtype new PDFAnnotation that allows files to be attached to the PDF. File attachments do not work in the free Acrobat Reader - they require the full version of Acrobat. Currently the "encrypt separately" option added in Acrobat 7 is not supported, although if the document is encrypted the attachment will be encrypted with it.

    Note in revisions prior to 2.6 this class dealt with the file internally. In 2.6 the EmbeddedFile handling was moved to a separate class, EmbeddedFile, which now handles all the details of the actual file.

    Since:
    2.4.4
    • Constructor Detail

      • AnnotationFile

        public AnnotationFile()
        Create a new File annotation. To actually set the attachment, the setFile() method must be called.
    • Method Detail

      • setType

        public void setType​(java.lang.String type,
                            java.awt.Color color)
        Set the type of attachment - the physical appearance on the page. The type must be one of the four pre-defined types (PushPin, Graph, Paperclip or Tag) or an IllegalArgumentException will be thrown.
        Parameters:
        type - the type of attachment - one of the four values listed above.
        color - the color of the attachment
      • setCustomAppearance

        public void setCustomAppearance​(java.lang.String type,
                                        PDFCanvas canvas)
        Set a custom appearance on this AnnotationFile. This is non-standard but allowed; PDF viewers should have no trouble displaying this annotation, although edits to it may result in the appearance being lost.
        Parameters:
        type - the optional "type" of this annotation, which may be one of the four standard types (PushPin, Graph, Paperclip or Tag), a custom value, or null for no type.
        canvas - the canvas for the appearance, which must not be null and must be flushed.
        Since:
        2.27.2
      • setRectangle

        public void setRectangle​(float x1,
                                 float y1,
                                 float x2,
                                 float y2)
        Set the Rectangle for this annotation. If setType() has been called to use a standard appearance for this annotation, since 2.18.2 the width and height of the rectangle will be overridden to the size of that type's appearance. A custom appearance can be any size.
        Overrides:
        setRectangle in class PDFAnnotation
        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
      • setFile

        public void setFile​(EmbeddedFile file)
        Set the contents of this annotation to the specified embedded file. The file can be shared - i.e. it can be referenced elsewhere in the PDF.
        Parameters:
        file - the EmbeddedFile object to attach, which must not be null.
        Since:
        2.6
      • getFile

        public EmbeddedFile getFile()
        Return the file embedded in this annotation
        Since:
        2.6
      • rebuild

        public void rebuild()
        Description copied from class: PDFAnnotation
        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.
        Overrides:
        rebuild in class PDFAnnotation
      • 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