/
PdfBuilder.cs
executable file
·163 lines (137 loc) · 5.87 KB
/
PdfBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using IT = iTextSharp.text;
namespace Talaran.Ldg {
public class PdfBuilder: IBuilder {
private int pos = 0;
private IT.IDocListener document;
private IT.pdf.PdfPTable table;
private const int COLUMNS = 5;
private const int SIZE_TITLE = 20;
private const int SIZE_ROW = 10;
private const float PAD_BOTTOM = 4F;
public PdfBuilder(IT.IDocListener document) {
if (document == null) {
throw new System.ArgumentNullException("document", "document cannot be null." );
}
this.document = document;
}
public void BeginReport(string title, int year) {
SetTable(title, year);
}
public void EndReport() {
document.Add(table);
document.NewPage();
}
public void Add(Athlete athete) {
// posizione
var ps =
new IT.Phrase((++pos).ToString(),
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD)
);
var cell = new IT.pdf.PdfPCell(ps);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
// evidenzia i primi 3
if (pos < 4) {
cell.GrayFill = 0.90F;
}
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
var data =
new IT.Phrase(athete.Id.ToString() ,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.NORMAL));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase(athete.Surname + " " + athete.Name,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.NORMAL));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase(athete.Year.ToString(),
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.NORMAL));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
string t = athete.Time == "99:99" ? "rit." : athete.Time;
data = new IT.Phrase(t,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.NORMAL));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_RIGHT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
}
private void SetTable(string titleString, int year) {
pos = 0;
var ed =
new IT.Phrase("Trofeo Luca De Gerone " + year.ToString() ,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_TITLE + 2, IT.Font.BOLD)
);
var title =
new IT.Phrase(titleString,
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_TITLE, IT.Font.BOLD)
);
//pos, pett, nome , anno tempo
float[] widths = {1f,1f,6f,2f,4f};
table = new IT.pdf.PdfPTable(widths);
table.HeaderRows = 2;
table.DefaultCell.Border = IT.Rectangle.NO_BORDER;
// edizione
var cell = new IT.pdf.PdfPCell(ed);
cell.HorizontalAlignment = IT.Element.ALIGN_CENTER;
cell.Colspan = COLUMNS;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
// intesatazione
cell = new IT.pdf.PdfPCell(title);
cell.HorizontalAlignment = IT.Element.ALIGN_CENTER;
cell.Colspan = COLUMNS;
cell.PaddingBottom = PAD_BOTTOM;
cell.GrayFill = 0.90F;
table.AddCell(cell);
// riga vuota
//table.AddCell(GetEmptyRow());
var data =
new IT.Phrase("Pos.",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data =
new IT.Phrase("Pett.",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase("Nome",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase("Anno",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_LEFT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
data = new IT.Phrase("Tempo",
IT.FontFactory.GetFont(IT.FontFactory.HELVETICA, SIZE_ROW, IT.Font.BOLD));
cell = new IT.pdf.PdfPCell(data);
cell.HorizontalAlignment = IT.Element.ALIGN_RIGHT;
cell.PaddingBottom = PAD_BOTTOM;
table.AddCell(cell);
}
private IT.pdf.PdfPCell GetEmptyRow() {
var cell = new IT.pdf.PdfPCell();
cell.Border = IT.Rectangle.NO_BORDER;
cell.HorizontalAlignment = IT.Element.ALIGN_CENTER;
cell.Colspan = COLUMNS;
cell.PaddingBottom = 20F;
return cell;
}
}
}