001/*
002 * $Id: PdfPageEventHelper.java 4784 2011-03-15 08:33:00Z blowagie $
003 *
004 * This file is part of the iText (R) project.
005 * Copyright (c) 1998-2011 1T3XT BVBA
006 * Authors: Bruno Lowagie, Paulo Soares, et al.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU Affero General Public License version 3
010 * as published by the Free Software Foundation with the addition of the
011 * following permission added to Section 15 as permitted in Section 7(a):
012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT,
013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
014 *
015 * This program is distributed in the hope that it will be useful, but
016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
017 * or FITNESS FOR A PARTICULAR PURPOSE.
018 * See the GNU Affero General Public License for more details.
019 * You should have received a copy of the GNU Affero General Public License
020 * along with this program; if not, see http://www.gnu.org/licenses or write to
021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
022 * Boston, MA, 02110-1301 USA, or download the license from the following URL:
023 * http://itextpdf.com/terms-of-use/
024 *
025 * The interactive user interfaces in modified source and object code versions
026 * of this program must display Appropriate Legal Notices, as required under
027 * Section 5 of the GNU Affero General Public License.
028 *
029 * In accordance with Section 7(b) of the GNU Affero General Public License,
030 * a covered work must retain the producer line in every PDF that is created
031 * or manipulated using iText.
032 *
033 * You can be released from the requirements of the license by purchasing
034 * a commercial license. Buying such a license is mandatory as soon as you
035 * develop commercial activities involving the iText software without
036 * disclosing the source code of your own applications.
037 * These activities include: offering paid services to customers as an ASP,
038 * serving PDFs on the fly in a web application, shipping iText with a closed
039 * source product.
040 *
041 * For more information, please contact iText Software Corp. at this
042 * address: sales@itextpdf.com
043 */
044package com.itextpdf.text.pdf;
045import com.itextpdf.text.Document;
046import com.itextpdf.text.Paragraph;
047import com.itextpdf.text.Rectangle;
048
049/**
050 * Helps the use of <CODE>PdfPageEvent</CODE> by implementing all the interface methods.
051 * A class can extend <CODE>PdfPageEventHelper</CODE> and only implement the
052 * needed methods.
053 *<p>
054 * Note: do not use Document.add() inside a page event.
055 * @author Paulo Soares
056 */
057
058public class PdfPageEventHelper implements PdfPageEvent {
059    
060/**
061 * Called when the document is opened.
062 *
063 * @param writer the <CODE>PdfWriter</CODE> for this document
064 * @param document the document
065 */
066    public void onOpenDocument(PdfWriter writer,Document document) {
067    }
068    
069/**
070 * Called when a page is initialized.
071 * <P>
072 * Note that if even if a page is not written this method is still
073 * called. It is preferable to use <CODE>onEndPage</CODE> to avoid
074 * infinite loops.
075 *
076 * @param writer the <CODE>PdfWriter</CODE> for this document
077 * @param document the document
078 */
079    public void onStartPage(PdfWriter writer,Document document) {
080    }
081    
082/**
083 * Called when a page is finished, just before being written to the document.
084 *
085 * @param writer the <CODE>PdfWriter</CODE> for this document
086 * @param document the document
087 */
088    public void onEndPage(PdfWriter writer,Document document) {
089    }
090    
091/**
092 * Called when the document is closed.
093 * <P>
094 * Note that this method is called with the page number equal
095 * to the last page plus one.
096 *
097 * @param writer the <CODE>PdfWriter</CODE> for this document
098 * @param document the document
099 */
100    public void onCloseDocument(PdfWriter writer,Document document) {
101    }
102    
103/**
104 * Called when a Paragraph is written.
105 * <P>
106 * <CODE>paragraphPosition</CODE> will hold the height at which the
107 * paragraph will be written to. This is useful to insert bookmarks with
108 * more control.
109 *
110 * @param writer the <CODE>PdfWriter</CODE> for this document
111 * @param document the document
112 * @param paragraphPosition the position the paragraph will be written to
113 */
114    public void onParagraph(PdfWriter writer,Document document,float paragraphPosition) {
115    }
116    
117/**
118 * Called when a Paragraph is written.
119 * <P>
120 * <CODE>paragraphPosition</CODE> will hold the height of the end of the paragraph.
121 *
122 * @param writer the <CODE>PdfWriter</CODE> for this document
123 * @param document the document
124 * @param paragraphPosition the position of the end of the paragraph
125 */
126    public void onParagraphEnd(PdfWriter writer,Document document,float paragraphPosition) {
127    }
128    
129/**
130 * Called when a Chapter is written.
131 * <P>
132 * <CODE>position</CODE> will hold the height at which the
133 * chapter will be written to.
134 *
135 * @param writer            the <CODE>PdfWriter</CODE> for this document
136 * @param document          the document
137 * @param paragraphPosition the position the chapter will be written to
138 * @param title             the title of the Chapter
139 */
140    public void onChapter(PdfWriter writer,Document document,float paragraphPosition,Paragraph title) {
141    }
142    
143/**
144 * Called when the end of a Chapter is reached.
145 * <P>
146 * <CODE>position</CODE> will hold the height of the end of the chapter.
147 *
148 * @param writer the <CODE>PdfWriter</CODE> for this document
149 * @param document the document
150 * @param position the position of the end of the chapter.
151 */
152    public void onChapterEnd(PdfWriter writer,Document document,float position) {
153    }
154    
155/**
156 * Called when a Section is written.
157 * <P>
158 * <CODE>position</CODE> will hold the height at which the
159 * section will be written to.
160 *
161 * @param writer            the <CODE>PdfWriter</CODE> for this document
162 * @param document          the document
163 * @param paragraphPosition the position the section will be written to
164 * @param depth                         the number depth of the Section
165 * @param title             the title of the section
166 */
167    public void onSection(PdfWriter writer,Document document,float paragraphPosition,int depth,Paragraph title) {
168    }
169    
170/**
171 * Called when the end of a Section is reached.
172 * <P>
173 * <CODE>position</CODE> will hold the height of the section end.
174 *
175 * @param writer the <CODE>PdfWriter</CODE> for this document
176 * @param document the document
177 * @param position the position of the end of the section
178 */
179    public void onSectionEnd(PdfWriter writer,Document document,float position) {
180    }
181    
182/**
183 * Called when a <CODE>Chunk</CODE> with a generic tag is written.
184 * <P>
185 * It is useful to pinpoint the <CODE>Chunk</CODE> location to generate
186 * bookmarks, for example.
187 *
188 * @param writer the <CODE>PdfWriter</CODE> for this document
189 * @param document the document
190 * @param rect the <CODE>Rectangle</CODE> containing the <CODE>Chunk</CODE>
191 * @param text the text of the tag
192 */
193    public void onGenericTag(PdfWriter writer,Document document,Rectangle rect,String text) {
194    }
195}