Transition and Duration : Page Event « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfTransition;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass extends PdfPageEventHelper {
  protected PdfTransition transition;

  protected int duration;

  public MainClass(PdfTransition transition, int duration) {
    this.transition = transition;
    this.duration = duration;
  }

  public void setTransition(PdfTransition transition) {
    this.transition = transition;
  }

  public void setDuration(int duration) {
    this.duration = duration;
  }

  public void onStartPage(PdfWriter writer, Document document) {
    writer.setTransition(transition);
    writer.setDuration(duration);
  }

  public static void main(String[] args) throws Exception {
    Document document = new Document(new Rectangle(144, 115));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    writer.setViewerPreferences(PdfWriter.PageModeFullScreen);
    MainClass slideshow = new MainClass(new PdfTransition(PdfTransition.OUTBOX), 1);
    writer.setPageEvent(slideshow);
    document.open();

    Image img0 = Image.getInstance("0.gif");
    img0.setAbsolutePosition(0, 0);
    document.add(img0);
    document.newPage();

    Image img1 = Image.getInstance("1.gif");
    img1.setAbsolutePosition(0, 0);
    document.add(img1);
    document.newPage();

    document.close();
  }
}








29.22.Page Event
29.22.1.extends PdfPageEventHelper
29.22.2.Pdf document footer
29.22.3.Pdf Page Event Helper
29.22.4.Set PageEvent to Pdf document
29.22.5.Pdf events: on chapter, on chapter end, on section, on document Close Document
29.22.6.Transition and Duration