Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java PDF: Gérer les événements open, close, page start et end d’un document PDF

Java PDF:  Gérer les événements open, close, page start et end d'un document PDF
{filelink=10396}

/***** Code de MesExemples.com *******/
/**
 * @(#)ExempleDocumentPageEventPDF.java
 *
 *
 * @author 
 *sakoba(java.mesexemples.com) @version 1.00 2013/4/27
 */
 
 
import java.io.FileOutputStream;
 
import com.itextpdf.text.Document;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfGState;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
 
public class ExempleDocumentPageEventPDF extends PdfPageEventHelper {
  public Image headerImage;
 
  public PdfPTable table;
 
  public PdfGState gstate;
 
  public PdfTemplate tpl;
 
  public BaseFont helv;
 
  public static void main(String args[]) {
    try {
      Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
      PdfWriter pdf_writer = PdfWriter.getInstance(doc, 
      	new FileOutputStream("c:/ExempleDocumentPageEventPDF.pdf"));
      pdf_writer.setPageEvent(new ExempleDocumentPageEventPDF());
      doc.open();
 
      Paragraph p = new Paragraph("text");
      doc.add(p);
 
      doc.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
  public void onOpenDocument(PdfWriter pdf_writer, Document document) {
    System.out.println("événement onOpenDocument géneré");
  }
 
  public void onEndPage(PdfWriter pdf_writer, Document document) {
    System.out.println("événement onEndPage géneré");
  }
 
  public void onStartPage(PdfWriter pdf_writer, Document document) {
    System.out.println("événement onStartPage géneré");
  }
 
  public void onCloseDocument(PdfWriter pdf_writer, Document document) {
    System.out.println("événement onCloseDocument géneré");
  }
}