Class AnnotationRichMedia

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class AnnotationRichMedia
    extends PDFAnnotation

    This class is a type of PDFAnnotation that acts as a container for interactive media such as video.

    For example, to embed an MP4 video in a page:

     EmbeddedFile file = new EmbeddedFile(new File("myfile.mp4"));
     file.setType("video/mp4");
     AnnotationRichMedia annot = new AnnotationRichMedia();
     annot.setFile(file);
     annot.setPage(page);
     annot.setRectangle(100, 600, 300, 800);
     
    Since:
    2.11.14
    • Constructor Detail

      • AnnotationRichMedia

        public AnnotationRichMedia()
        Creates a new rich-media annotation.
    • Method Detail

      • setPreferredType

        public void setPreferredType​(java.lang.String type)
        Set the preferred type of rich-media this annotation should represent. Valid values are "Screen" or "RichMedia" - anything will let the API choose an appropriate value. This must be called before setFile(org.faceless.pdf2.EmbeddedFile) to have an effect.
        Since:
        2.26.3
      • setFile

        public void setFile​(EmbeddedFile file)

        Set the content of this rich media annotation to a particular file. This can be used to embed a video. The supplied file must have a type which is used to inform the API as to the best way to embed the file.

        The current list of supported type is deliberately left undefined but includes the following, all of which have had basic testing in Acrobat in 2022. However please bear in mind that support has come and gone over the years and is likely to be at least partly platform dependent.

        • video/mp4 (h264 codec strongly recommended)
        • audio/mpeg (aka mp3)
        • model/u3d
        • model/prc
        Parameters:
        file - the file to embed, which which have a type and should have both a name and description.
        Since:
        2.24.2
      • setAppearance

        public void setAppearance​(PDFCanvas canvas)
        If the RichMedia is not loaded yet, or cannot be loaded for some reason, this method can set a fallback visualization for the annotation. The supplied canvas will be stretched to fit the final rectangle of the annotation, so the size does not have to match.
        Parameters:
        canvas - the apperarance of the annotation, or null for no appearance.
        Since:
        2.24.2
      • getFiles

        public java.util.Map<java.lang.String,​EmbeddedFile> getFiles()
        Return an unmodifiable map of all the assets in this rich-media annotation. For many annotations this will contain only one item.
        Since:
        2.26.3
      • 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