Class AnnotationRichMedia

  • All Implemented Interfaces:

    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"));
     AnnotationRichMedia annot = new AnnotationRichMedia();
     annot.setRectangle(100, 600, 300, 800);
    • Constructor Detail

      • AnnotationRichMedia

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

      • setPreferredType

        public void setPreferredType​(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.
      • 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
        file - the file to embed, which which have a type and should have both a name and description.
      • 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.
        canvas - the apperarance of the annotation, or null for no appearance.
      • getFiles

        public Map<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.
      • toString

        public String toString()
      • putLiteral

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