View Javadoc

1   /***
2    * 
3    */
4   package org.telscenter.pas.ui.pdf;
5   
6   import java.text.SimpleDateFormat;
7   import java.util.Date;
8   
9   import com.lowagie.text.Chunk;
10  import com.lowagie.text.Element;
11  import com.lowagie.text.Font;
12  import com.lowagie.text.Paragraph;
13  import com.lowagie.text.pdf.PdfPCell;
14  import com.lowagie.text.pdf.PdfPTable;
15  
16  /***
17   * @author anthonyperritano
18   *
19   */
20  public class PDFUtil {
21  	
22  	
23  	public static int defaultFont =  Font.TIMES_ROMAN;
24  	
25  	public PDFUtil() {
26  		super();
27  		// TODO Auto-generated constructor stub
28  	}
29  	
30  	public static PdfPTable createStepTitle(String noteTitle) {
31  		PdfPTable table = new PdfPTable(1);
32  		Font font = new Font(defaultFont, 11, Font.BOLD);
33  		PdfPCell stepTitleCell =
34  			  new PdfPCell(new Paragraph(noteTitle,font));
35  		stepTitleCell.setBorderWidthLeft(0.0f);
36  		stepTitleCell.setBorderWidthRight(0.0f);
37  		stepTitleCell.setBorderWidthTop(0.0f);
38  		stepTitleCell.setBorderWidthBottom(0.0f);
39  		stepTitleCell.setPaddingLeft(6.0f);
40  		table.addCell(stepTitleCell);
41  		stepTitleCell.setBorderWidth(0);
42  		return table;
43  	}
44  
45  	public static PdfPCell createActivityTitle(String titleText) {
46  		Font font = new Font(defaultFont, 12, Font.BOLD);
47  		PdfPCell cell =
48  			  new PdfPCell(new Paragraph(titleText,font));
49  		cell.setBorderWidthLeft(1.0f);
50  		cell.setBorderWidthRight(1.0f);
51  		cell.setBorderWidthTop(1.0f);
52  		cell.setBorderWidthBottom(1.0f);
53  		cell.setPaddingBottom(4.0f);
54  		cell.setPaddingLeft(0.0f);
55  		cell.setBorderWidth(0);
56  		return cell;
57  	}
58  	
59  	public static PdfPCell createEmptyCell() {
60  		PdfPCell cell =
61  			  new PdfPCell(new Paragraph("\n"));
62  		cell.setBorderWidthLeft(0.0f);
63  		cell.setBorderWidthRight(0.0f);
64  		cell.setBorderWidthTop(0.0f);
65  		cell.setBorderWidthBottom(0.0f);
66  		cell.setPaddingBottom(0.0f);
67  		cell.setPaddingLeft(0.0f);
68  		cell.setBorderWidth(0);
69  		return cell;
70  	}
71  	/***
72  	 * @return
73  	 */
74  	public static Element createHeading(String userNameStr, String projectTitleStr) {
75  		Font font = new Font(defaultFont, 10, Font.BOLD);
76  		Chunk userName = new Chunk(userNameStr+"\n",font);
77  	
78  		Chunk projectTitle = new Chunk("Work Report for project: " + projectTitleStr + "\n", font);
79  		Date date = new Date();
80  		SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
81  		Chunk dateLabel = new Chunk(df.format(date),font);
82  		
83  		Paragraph p1 = new Paragraph();
84  		p1.add(userName);
85  		p1.add(projectTitle);
86  		p1.add(dateLabel);
87  		return p1;
88  	}
89  	
90  	public static String getSlashDate() {
91  		Date date = new Date();
92  		SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
93  		return df.format(date);
94  	}
95  	
96  	public static String getNonSlashDate() {
97  		Date date = new Date();
98  		SimpleDateFormat df = new SimpleDateFormat("MMddyyyy");
99  		return df.format(date);
100 	}
101 
102 }