001: /*
002: * Copyright 2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.util;
017:
018: import java.text.SimpleDateFormat;
019: import java.util.Date;
020:
021: import com.lowagie.text.Document;
022: import com.lowagie.text.ExceptionConverter;
023: import com.lowagie.text.Font;
024: import com.lowagie.text.Phrase;
025: import com.lowagie.text.Rectangle;
026: import com.lowagie.text.pdf.PdfPCell;
027: import com.lowagie.text.pdf.PdfPTable;
028: import com.lowagie.text.pdf.PdfPageEventHelper;
029: import com.lowagie.text.pdf.PdfWriter;
030:
031: /**
032: * This class is used to help generate PDF output
033: */
034: public class PDFPageHelper extends PdfPageEventHelper {
035: private Date runDate;
036: private Font headerFont;
037: private String title;
038:
039: /**
040: * Generates output for end page
041: *
042: * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
043: */
044: public void onEndPage(PdfWriter writer, Document document) {
045: try {
046: Rectangle page = document.getPageSize();
047: PdfPTable head = new PdfPTable(3);
048: SimpleDateFormat sdf = new SimpleDateFormat(
049: "MM/dd/yyyy HH:mm:ss");
050: PdfPCell cell = new PdfPCell(new Phrase(
051: sdf.format(runDate), headerFont));
052: cell.setBorder(Rectangle.NO_BORDER);
053: head.addCell(cell);
054:
055: cell = new PdfPCell(new Phrase(title, headerFont));
056: cell.setBorder(Rectangle.NO_BORDER);
057: cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
058: head.addCell(cell);
059:
060: cell = new PdfPCell(new Phrase("Page: "
061: + new Integer(writer.getPageNumber()), headerFont));
062: cell.setBorder(Rectangle.NO_BORDER);
063: cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
064: head.addCell(cell);
065:
066: head.setTotalWidth(page.width() - document.leftMargin()
067: - document.rightMargin());
068: head.writeSelectedRows(0, -1, document.leftMargin(), page
069: .height()
070: - document.topMargin() + head.getTotalHeight(),
071: writer.getDirectContent());
072: } catch (Exception e) {
073: throw new ExceptionConverter(e);
074: }
075: }
076:
077: /**
078: * Gets the headerFont attribute.
079: *
080: * @return Returns the headerFont.
081: */
082: public Font getHeaderFont() {
083: return headerFont;
084: }
085:
086: /**
087: * Sets the headerFont attribute value.
088: *
089: * @param headerFont The headerFont to set.
090: */
091: public void setHeaderFont(Font headerFont) {
092: this .headerFont = headerFont;
093: }
094:
095: /**
096: * Gets the runDate attribute.
097: *
098: * @return Returns the runDate.
099: */
100: public Date getRunDate() {
101: return runDate;
102: }
103:
104: /**
105: * Sets the runDate attribute value.
106: *
107: * @param runDate The runDate to set.
108: */
109: public void setRunDate(Date runDate) {
110: this .runDate = runDate;
111: }
112:
113: /**
114: * Gets the title attribute.
115: *
116: * @return Returns the title.
117: */
118: public String getTitle() {
119: return title;
120: }
121:
122: /**
123: * Sets the title attribute value.
124: *
125: * @param title The title to set.
126: */
127: public void setTitle(String title) {
128: this.title = title;
129: }
130: }
|