Java Tutorial/PDF/Document Action

Материал из Java эксперт
Версия от 05:20, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

event for closing

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    document.add(new Paragraph("event for closing"));
    writer.setAdditionalAction(PdfWriter.DOCUMENT_CLOSE, PdfAction.javaScript(
        "app.alert("Thank you for reading this document.");\r", writer));

    
    document.close();
  }
}





Page open / close action

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    document.add(new Paragraph("alert messages."));
    writer.setPageAction(PdfWriter.PAGE_OPEN, PdfAction.javaScript(
        "app.alert("You have reached page 3");\r", writer));
    writer.setPageAction(PdfWriter.PAGE_CLOSE, PdfAction.javaScript(
        "app.alert("You have left page 3");\r", writer));
    document.add(new Paragraph("Page 3"));
    document.close();
  }
}