PDFlib
KAUFEN
PDFlib

interactive/movie_annotations

Demonstrate the use of a movie annotation in PDF.

Download Java Code     Show Output PDF

/* $Id: movie_annotations.java,v 1.2 2008/04/08 13:46:02 katja Exp $

 * Movie annotations:

 * Demonstrate the use of a movie annotation in PDF.

 *

 * Required software: PDFlib Lite/PDFlib/PDFlib+PDI/PPS 7.0.3

 * Required data: movie file

 */

package com.pdflib.cookbook.pdflib.interactive;


import com.pdflib.pdflib;

import com.pdflib.PDFlibException;


public class movie_annotations

{

    public static void main (String argv[])

    {

    /* This is where the data files are. Adjust as necessary */

    String searchpath = "../input";

    String outfile = "movie_annotations.pdf";

    String title = "Movie Annotations";

   

    pdflib p = null;


    /* movie file to be referenced by the link */

    String moviefile = "../input/ski.avi";


    String optlist;

    int font, action;


    try {

        p = new pdflib();


        /* This means we must check return values of load_font() etc. */

        p.set_parameter("errorpolicy", "return");


        p.set_parameter("SearchPath", searchpath);


        if (p.begin_document(outfile, "") == -1)

            throw new Exception("Error: " + p.get_errmsg());


        p.set_info("Creator", "PDFlib Cookbook");

        p.set_info("Title", title + " $Revision: 1.2 $");


        font = p.load_font("Helvetica", "unicode", "");

        if (font == -1)

            throw new Exception("Error: " + p.get_errmsg());


        p.begin_page_ext(0, 0, "width=a4.height height=a4.width");



        /* Create a "Movie" action for playing the movie */

        action = p.create_action("Movie", "target=mymovie");

               

        /* Option list for the Link annotation to play a movie.

         * "showcontrols" shows a controller bar while playing the movie.

         * "movieposter auto" displays a poster image retrieved from the movie

         * file.

         * "playmode open" plays the movie once and leaves the movie controller

         * bar open.

         */

        optlist = "name=mymovie action={activate " + action + "} linewidth=0 " +

            "filename=" + moviefile + " showcontrols movieposter=auto " +

            "playmode=open";

       

        /* Create a Link annotation with the "Movie" action.

         */

        p.create_annotation(150, 300, 300, 400, "Movie", optlist);


        p.end_page_ext("");


        p.end_document("");


        } catch (PDFlibException e) {

            System.err.print("PDFlib exception occurred:\n");

            System.err.print("[" + e.get_errnum() + "] " + e.get_apiname() +

                ": " + e.get_errmsg() + "\n");

        } catch (Exception e) {

            System.err.println(e.getMessage());

        } finally {

            if (p != null) {

                p.delete();

            }

        }

    }

}