Java tutorial
import java.io.FileOutputStream; import com.lowagie.text.Document; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.PdfPageEventHelper; import com.lowagie.text.pdf.PdfWriter; public class PdfEvents { public static void main(String[] args) { Document document = new Document(PageSize.A4, 80, 50, 30, 65); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PdfEvents.pdf")); document.open(); writer.setPageEvent(new MyPageEvents()); document.newPage(); document.add(new Paragraph("Text")); document.close(); } catch (Exception e) { System.err.println(e.getMessage()); } } } class MyPageEvents extends PdfPageEventHelper { public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) { System.out.println("onGenericTag"); } public void onOpenDocument(PdfWriter writer, Document document) { System.out.println("onOpenDocument"); } public void onChapter(PdfWriter writer, Document document, float paragraphPosition, Paragraph title) { System.out.println("onChapter"); } public void onEndPage(PdfWriter writer, Document document) { System.out.println("onEndPage"); } public void onCloseDocument(PdfWriter writer, Document document) { System.out.println("onCloseDocument"); } }