-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoiceDocument.cs
329 lines (288 loc) · 14.2 KB
/
InvoiceDocument.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
using QuestPDF.Drawing;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace ResumePDF
{
internal class InvoiceDocument : IDocument
{
public InvoiceModel? Model { get; } = default;
public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
public float LeftRatio = 1.15f; //the ratio of the right side to the total space rg. 1.1/2
public float headerMaxHeight = 135f; //the ratio of the right side to the total space rg. 1.1/2
string[] fonts => Directory.GetFiles(@"Fonts\Ubuntu\", "*.ttf"); //get font file names
public InvoiceDocument()
{
//Model = model;
//foreach (var font in fonts)
//{
// //Console.WriteLine("Font locationo is" + font);
// FontManager.RegisterFont(File.OpenRead(font));
//}
}
public void Compose(IDocumentContainer container)
{
container.Page(page =>
{
//page.Margin(10);
page.Header().Background(Colors.White).Element(ComposeHeader);
page.Content().Background(Colors.White).Element(ComposeContent);
page.Footer().Background(Colors.White).Element(ComposeFooter);
//page.Footer().AlignCenter().Text(x =>
//{
// x.CurrentPageNumber();
// x.Span(" / "); x.TotalPages();
//});
});
}
void ComposeHeader(IContainer container)
{
container.Column(column =>
{
column.Item().ShowOnce().Element(SingleHeader);
//column.Item().SkipOnce().Background(Colors.Green.Lighten2).Height(40);
});
void SingleHeader(IContainer container)
{
container.MaxHeight(headerMaxHeight)
//.Background(Colors.Grey.Lighten2)
.PaddingTop(5)
.PaddingRight(15)
.Row(row =>
{
//Left Side - Resume Brief
row.RelativeItem(LeftRatio)
//.Border(1)
.Component(DataSource.LeftHeader);
//row.ConstantItem(100).Height(50).Placeholder();
//Right Side - Contact information
row.RelativeItem()
//.Border(1)
.AlignRight()
//.Component(new LoremPicsum(false));
.Component(DataSource.RightHeader);
});
}
//container.Dynamic(new ProgressComponent());
//container.Dynamic(new FibonacciHeader(3,5));
//container.Element
//container.Component(new DecorComponent());
}
void ComposeContent(IContainer container)
{
//container.PaddingVertical(10)
const float rightPadding = -120f;
const float left_RightPadding = 100f;
const float left_LeftPadding = -16;
const float generalPadding = 5f;
container.BorderTop(1)
//.Height(695)
.Border(1)
//.Background(Colors.Grey.Lighten3)
//.AlignCenter()
.PaddingTop(generalPadding)
//.AlignMiddle()
.Row(row =>
{
//ENSURE SPACE BEtween columns
row.Spacing(30
);
//Left side of Resume Content
row.RelativeItem(LeftRatio)
//.Border(1)
.PaddingRight(rightPadding)
//.Background(Colors.Grey.Lighten1)
.Column(column =>
{
column.Spacing(-2);
foreach (var leftItem in DataSource.ReadLeftContent())
{
column.Item().Decoration(decoration =>
{
//title
decoration.Before()
//.PaddingRight(left_RightPadding)
.PaddingLeft(left_LeftPadding)
.Text(" " + leftItem.Title)
.Style(TypographyStyles.Title2);
//body
decoration.Content()
.PaddingRight(left_RightPadding)
.Component(leftItem.component);
});
}
//for work experience - Row 2
//column.Item().Decoration(decoration =>
//{
// //title
// decoration.Before()
// .PaddingRight(left_RightPadding)
// .Text(" " + "WORK EXPERIENCE")
// .Style(TypographyStyles.Title2);
// //body
// decoration.Content()
// .Element(showExpBullets);
// void showExpBullets(IContainer container)
// {
// //inner column to place bullets
// container.Column(column =>
// {
// //DataSource.EducationComponent
// // .ForEach(bitem => column.Item().ShowEntire().PaddingRight(10).Component(bitem));
// foreach (var bulletItem in DataSource.WorkExperienceComponent)
// { column.Item().ShowEntire().PaddingRight(10).Component(bulletItem); }
// });
// }
//});
});
//right side of resume content
row.RelativeItem()
.PaddingRight(generalPadding)
//.Background(Colors.Grey.Lighten1)
.Column(column =>
{
column.Spacing(generalPadding);
foreach (var rightItem in DataSource.ReadRightContent())
{
//Skills section
column.Item().Decoration(decoration =>
{
//title
decoration.Before()
.Text(rightItem.Title)
.Style(TypographyStyles.Title2);
//body
decoration.Content()
.ShowOnce()
.Component(rightItem.component);
});
}
//Certificates section
//column.Item().Decoration(decoration =>
//{
// //title
// decoration.Before()
// .Text(DataSource.CertificatesComponent.BasicList.Title)
// .Style(TypographyStyles.Title2);
// //body
// decoration.Content()
// .Component(DataSource.CertificatesComponent);
//});
////Personal Projects section
//column.Item().Decoration(decoration =>
//{
// //title
// decoration.Before()
// .Text(DataSource.ProjectsComponent.BasicList.Title)
// .Style(TypographyStyles.Title2);
// //body
// decoration.Content()
// .Component(DataSource.ProjectsComponent);
//});
////Interests section
//column.Item().Decoration(decoration =>
//{
// //title
// decoration.Before()
// .Text(DataSource.InterestsComponent.highlightItems.Title)
// .Style(TypographyStyles.Title2);
// //body
// decoration.Content()
// .Component(DataSource.InterestsComponent);
//});
});
//Text at the bottom
});
}
void ComposeFooter(IContainer container)
{
var footerString = Utils.ParseJson<JsonString>("Data/Footer/Footer.json");
container.AlignCenter()
//.Border(1)
.Text(footerString?.Value)
.Style(TypographyStyles.Normal);
}
void ComposeBrokenContent(IContainer container)
{
container.PaddingVertical(40).Column(column =>
{
column.Spacing(5);
column.Item().Row(row =>
{
row.RelativeItem().Component(new MockAddressCompnent("From", Model.SellerAddress));
row.ConstantItem(50);
row.RelativeItem().Component(new MockAddressCompnent("To", Model.CustomerAddress));
});
column.Item().Element(ComposeTable);
var totalPrice = Model.Items.Sum(x => x.Price * x.Quantity);
column.Item()
.AlignRight()
.Text($"Grand total: {totalPrice}$")
.FontSize(14);
if (!String.IsNullOrEmpty(Model.Comments))
{
column.Item().PaddingTop(25).Element(ComposeComments);
}
});
}
void ComposeTable(IContainer container)
{
//container.Height(250)
// .Background(Colors.Grey.Lighten3)
// .AlignCenter()
// .AlignMiddle()
// .Text("Table Text")
// .FontSize(16);
container.Table(table =>
{
table.ColumnsDefinition(columns =>
{
columns.ConstantColumn(25);
columns.RelativeColumn(3);
columns.RelativeColumn();
columns.RelativeColumn();
columns.RelativeColumn();
});
table.Header(header =>
{
static IContainer CellStyle(IContainer container)
{
return container.DefaultTextStyle(x => x.SemiBold())
.PaddingVertical(5)
.BorderBottom(1)
.BorderColor(Colors.Black);
}
header.Cell().Element(CellStyle).Text("#");
header.Cell().Element(CellStyle).Text("Product");
header.Cell().Element(CellStyle).AlignRight().Text("Unit Price");
header.Cell().Element(CellStyle).AlignRight().Text("Qualtity");
header.Cell().Element(CellStyle).AlignRight().Text("Total");
});
foreach (var item in Model.Items)
{
static IContainer CellStyle(IContainer container)
{
return container.BorderBottom(1)
.BorderColor(Colors.Grey.Lighten3)
.PaddingVertical(5);
}
table.Cell().Element(CellStyle).Text(Model.Items.IndexOf(item) + 1);
table.Cell().Element(CellStyle).Text(item.Name);
table.Cell().Element(CellStyle).AlignRight().Text($"{item.Price}$");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.Quantity}$");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.Quantity * item.Price}$");
}
});
}
void ComposeComments(IContainer container)
{
container.Background(Colors.Grey.Lighten1)
.Padding(10).Column(column =>
{
column.Spacing(5);
column.Item().Text("Comments").FontSize(14);
column.Item().Text(Model.Comments);
});
}
}
}