Bo Zhang's Homepage
..The universe is unfolding as it should..

2006-7-11

[转载] PDF with animations

归档于: 本站文摘 @ 2:58 pm

Jens Uwe Nöckel

系里的老师推荐的东西,在PDF文件中插入动画的教程,前提是了解LaTeX的基本使用,且动画文件的格式合适(如avi)。文章的来源是这里。实习期间实在紧张,来不及翻译,就直接贴原文了。



Including animations in PDF using LaTeX

The Portable Document Format (PDF) is much more than just a substitute for paper. While printable documents are thought of as static, PDF can be dynamic and interactive. Recently, there have been reports on a new technology called livepaper (sorry, couldn’t find a good link in English) which is built on Flash, claiming to be better than E-paper and HTML because of its multimedia features. But I cannot find anything in those "innovations" that PDF can’t already do (see for example these interactivity demos). In fact, since Adobe has acquired Macromedia, some convergence of PDF and Flash might be expected in the future. But if you go through my example on this page, it will be clear that PDF all by itself at this point in time has all the features a multimedia author could ask for.

The context of this page is the problem of how to prepare scientific/technical documents. If you have looked at my suggestions for doing scientific presentations using Apple’s Keynote 2, you should be convinced by now that LaTeX is an essential ingredient for any computer-based talk with mathematical content.

In particular, I included some links to LaTeX-based PDF presentation tools that can do almost anything that Keynote can do, based on the power of Adobe Reader.

 

The movie15 Package

However, one thing that isn’t explained very well on other web sites is how to put multimedia content into PDF presentations. If you look at the manual for the LaTeX beamer class, there is in fact a rather detailed description of the necessary commands for movie or sound inclusion. Use that approach if you are developing a really fancy presentation.

On this page, I’ll describe the approach that is best suited for a small, "bare-bones" presentation without much stylistic overhead. To do this, you should use the LaTeX style called movie15.sty created by Alexander Grahn (as of October 2005, this package is fully functional with Mac OS X). To check whether your LaTeX installation contains this style, just typeset the movie.tex file below and see if it gives you an error message. In that case, you’ll need to donwload the style file:

Installation is simple: move movie15.sty to a place where latex can find it (i.e., in a local texmf directory), and invoke texhash to make latex aware of the new file (if you want to test this first, just put the style file into the same directory as your tex document and invoke pdflatex). The movie15 download also includes documentation and an example. In the following, I’ll walk you through my own example.

 

How is it done?

Prerequisites

PDF movies can be displayed with Adobe Reader. In case you encounter problems on a Mac running Tiger (OS X 10.4+), make sure you have the most recent version (7.05 or higher) of Adobe Reader. The Preview Application is not an alternative here because it does not handle multimedia plugins. There are no problems with older version of Adobe Reader on Mac OS Panther, as far as I can tell.

Also note that you cannot use acroread to display multimedia embedded with the help of this package. In other words, Linux platforms can be used only to create the PDF movies, but not to present them.

Creating the files

For several years, the way I’ve been putting movies into PDF presentations has been based on direct application of pdfannot or pdfmark - commands understood by pdflatex which allow you to write PDF code. The style movie15.sty uses these commands to create a very flexible and user-friendly way to do this without having to leave the LaTeX level. This package is able to use the features of the newest Adobe Reader, including 3D virtual reality interactivity. Here, I’ll address only traditional movie playback to keep things simple.

The method is best described by example.

  1. Assume you have the following movie in MPEG or AVI format (actually, I have an mp4 movie on this web page but will use avi for the PDF example below):

    To try the example below, download one or both of these movie files:

    Circle-m-increase3.avi
    Circle-m-increase3.mp4
    by right-clicking on the file name.

    s used for this example because I’m hoping it is more compatible with media players, but especially for web documents I would recommend MPEG encoding. If you want, you can modify the example below by replacing .avi with .mp4 in the LaTeX source.

    To create MPEG format
    , here are some tools:

    • QT amateur is a free movie player for Mac OS X which can export various movie and image file formats (even in batch mode). It requires Quicktime 7 to be installed on your machine.
    • Apple’s Quicktime Pro application has more flexibility but it’s not free.
    • If you are comfortable with command-line UNIX tools, there are the free packages mpeg2vidcodec or mpegencode, available for Mac from the porting system fink.

    For additional information, see the pages on making movies.

    Flash movies work, too, and this opens additional possibilities for interactivity in your PDF document.

  2. You can see how I embedded the movie into the HTML code of this very page, and now we want to do the exact same thing with a PDF file by using pdflatex.

    To do this, create a LaTeX file (named, e.g., movie.tex) in the same directory as the movie, containing the following:

    documentclass[12pt,landscape]{article}
    usepackage{geometry}
    geometry{verbose,letterpaper}
    usepackage{movie15}
    usepackae{hyperref}
    begin{document}
    Whispering-gallery mode in a quarter circle:
    begin{figure}[ht]
    includemovie[
      poster,
      text=(Loading Circle-m-increase3.avi)
    ]{6cm}{6cm}{Circle-m-increase3.avi}
    end{figure}
    end{document}
    

    The LaTeX file is downloadable by clicking here.

    The includemovie command is the crucial object here. Its last three arguments are the dimensions of the movie and the file name. The dimensions can be chosen arbitrarily and will cause the movie to be rescaled accordingly.

    The commands related to geometry and landscape are not essential; they just turn the output page sideways for on-screen viewing. I added the package hyperref even though it gets loaded automatically when pdflatex is invoked. The reason I put this in is that the file can then be processed either using pdflatex movie (the preferred way) or using latex movie followed by dvipdf movie to create the PDF output.

  3. In order to view the PDF with embedded movie, you need to open movie.pdf with Adobe Reader or Acrobat. The output file can also be downloaded by clicking here. The movie is automatically loaded and represented by its first frame (”poster frame”). Playback starts after you click on the picture and stops on the last frame. I didn’t put in any visible movie controls because they appear to be buggy under Windows (thanks to Alexander Grahn for mentioning this). With Mac OS X, controls work fine, so you could add the option controls to includemovie and obtain the same appearance as on this web page. Even without control buttons, one can always restart the movie by double-clicking on it (this applies to Mac; for Windows, you may just need a single click).

    One more warning: we are using advanced features of PDF here, so you also need a recent version (>1.2) of pdflatex, so upgrade your tex distribution if necessary.

Observe one fascinating detail:
The movie itself is contained in the PDF file, instead of having to be shipped as a separate file. In other words, we have created something that deserves the name Portable Document Format. The caveat of course is that the movie (or any other multimedia content for that matter) will only play properly if the PDF viewer manages to find an external program that can read the embedded file format. That is why it is not advisable to use exotic or platform-specific video formats (e.g., .WMV) if you want to send your PDF file to other people.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

首页 | 天文 | 科学 | 摄影 | 模型 | CV | 版权声明 | 联系站长
京ICP备05002854号-2 Powered by WordPress Version 2.0.6
Licensed under Creative Commons Licenses

porno izle