|
public>PhonebookPdfView extends AbstractPdfView {
private static final Font HEADLINE_FONT = new Font( Font.TIMES_ROMAN , 18,
Font.BOLD, Color.black );
private static final Font DATA_HEAD_FONT = new Font( Font.TIMES_ROMAN, 10,
Font.BOLD, Color.black );
private static final Font TEXT_FONT = new Font( Font.TIMES_ROMAN, 8,
Font.NORMAL,
Color.black );
private static final Font FOOTER_FONT = new Font( Font.TIMES_ROMAN, 5,
Font.NORMAL,
Color.black );
private static final int NO_OF_COLUMNS = 5;
/** Creates a new instance of PhonebookPdfView */
public PhonebookPdfView() {
}
protected void buildPdfMetadata(Map model, Document document,
HttpServletRequest request) {
document.addTitle("Phone Book");
document.addCreator("Arun Chhatpar");
}
protected void buildPdfDocument(
Map model,
Document doc,
PdfWriter writer,
HttpServletRequest req,
HttpServletResponse resp)
throws Exception {
List phonebook = (List) model.get("phonebook");
String>
Paragraph h1 = new Paragraph(title, HEADLINE_FONT);
h1.setAlignment(Paragraph.ALIGN_CENTER);
doc.add(h1);
doc.add(new Paragraph(" "));
doc.add(new Paragraph(" "));
doc.add(new Paragraph(" "));
// We create a table for used criteria and extracting information
PdfPTable table = new PdfPTable(NO_OF_COLUMNS);
int headerwidths[] = {20, 20, 20, 20, 20};
table.setWidths(headerwidths);
table.setWidthPercentage(100);
table.getDefaultCell().setBorderWidth(1);
table.getDefaultCell().setBorderColor(Color.black);
table.getDefaultCell().setPadding(3);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(new Phrase("Name", DATA_HEAD_FONT));
table.addCell(new Phrase("Home Phone", DATA_HEAD_FONT));
table.addCell(new Phrase("Work Phone", DATA_HEAD_FONT));
table.addCell(new Phrase("Cell Phone", DATA_HEAD_FONT));
table.addCell(new Phrase("Email", DATA_HEAD_FONT));
// We set the above row as>
// and adjust properties for normal cells
table.setHeaderRows(1);
table.getDefaultCell().setBorderWidth(1);
// We iterate now on the Phonebook list
Iterator it = phonebook.iterator();
while(it.hasNext()) {
PhonebookEntry pEntry = (PhonebookEntry) it.next();
table.addCell(new Phrase(pEntry.getFirstName() + " " +
pEntry.getLastName(),
TEXT_FONT));
table.addCell(new Phrase(pEntry.getHomeNumber(), TEXT_FONT));
table.addCell(new Phrase(pEntry.getWorkNumber(), TEXT_FONT));
table.addCell(new Phrase(pEntry.getCellNumber(), TEXT_FONT));
table.addCell(new Phrase(pEntry.getEmail(), TEXT_FONT));
}
doc.add(table);
doc.add(new Paragraph(" "));
doc.add(new Paragraph(" "));
doc.add(new Paragraph(" "));
doc.add(new Paragraph(" "));
String footerStr1 = "This example is developed to demonstrate the Spring
framework on the Geronimo Application Server.";
String footerStr2 = "This example is designed purely for
demonstrating the capabilities of the framework. It should under no
circumstances be used for production use.";
Paragraph footer1 = new Paragraph(footerStr1, FOOTER_FONT);
footer1.setAlignment(Paragraph.ALIGN_CENTER);
doc.add(footer1);
Paragraph footer2 = new Paragraph(footerStr2, FOOTER_FONT);
footer2.setAlignment(Paragraph.ALIGN_CENTER);
doc.add(footer2);
}
}
|
|
|