forked from VahidN/PdfReport.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageFilePathPdfReport.cs
More file actions
152 lines (147 loc) · 6.47 KB
/
ImageFilePathPdfReport.cs
File metadata and controls
152 lines (147 loc) · 6.47 KB
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
using System;
using System.Collections.Generic;
using iTextSharp.text.pdf;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PdfRpt.Core.Contracts;
using PdfRpt.Core.FunctionalTests.Models;
using PdfRpt.FluentInterface;
namespace PdfRpt.Core.FunctionalTests
{
[TestClass]
public class ImageFilePathPdfReport
{
[TestMethod]
public void Verify_ImageFilePathPdfReport_Can_Be_Created()
{
var report = CreateImageFilePathPdfReport();
TestUtils.VerifyPdfFileIsReadable(report.FileName);
}
public IPdfReportData CreateImageFilePathPdfReport()
{
return new PdfReport().DocumentPreferences(doc =>
{
doc.RunDirection(PdfRunDirection.LeftToRight);
doc.Orientation(PageOrientation.Portrait);
doc.PageSize(PdfPageSize.A4);
doc.DocumentMetadata(new DocumentMetadata { Author = "Vahid", Application = "PdfRpt", Keywords = "Test", Subject = "Test Rpt", Title = "Test" });
doc.Compression(new CompressionSettings
{
EnableCompression = true,
EnableFullCompression = true
});
})
.DefaultFonts(fonts =>
{
fonts.Path(TestUtils.GetVerdanaFontPath(),
TestUtils.GetTahomaFontPath());
fonts.Size(9);
fonts.Color(System.Drawing.Color.Black);
})
.PagesFooter(footer =>
{
footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy"));
})
.PagesHeader(header =>
{
header.CacheHeader(cache: true); // It's a default setting to improve the performance.
header.DefaultHeader(defaultHeader =>
{
defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
defaultHeader.ImagePath(TestUtils.GetImagePath("01.png"));
defaultHeader.Message("Our new rpt.");
});
})
.MainTableTemplate(template =>
{
template.BasicTemplate(BasicTemplate.SnowyPineTemplate);
})
.MainTablePreferences(table =>
{
table.ColumnsWidthsType(TableColumnWidthType.Relative);
})
.MainTableDataSource(dataSource =>
{
var listOfRows = new List<ImageRecord>
{
new ImageRecord
{
Id=1,
ImagePath = TestUtils.GetImagePath("01.png"),
Name = "Rnd"
},
new ImageRecord
{
Id=2,
ImagePath = TestUtils.GetImagePath("02.png"),
Name = "Bug"
},
new ImageRecord
{
Id=3,
ImagePath = TestUtils.GetImagePath("03.png"),
Name = "Stuff"
},
new ImageRecord
{
Id=4,
ImagePath = TestUtils.GetImagePath("04.png"),
Name = "Sun"
}
};
dataSource.StronglyTypedList(listOfRows);
})
.MainTableColumns(columns =>
{
columns.AddColumn(column =>
{
column.PropertyName("rowNo");
column.IsRowNumber(true);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(0);
column.Width(1);
column.HeaderCell("#");
});
columns.AddColumn(column =>
{
column.PropertyName<ImageRecord>(x => x.Id);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(1);
column.Width(3);
column.HeaderCell("Id");
column.ColumnItemsTemplate(t => t.Barcode(new Barcode39()));
});
columns.AddColumn(column =>
{
column.PropertyName<ImageRecord>(x => x.ImagePath);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(2);
column.Width(3);
column.HeaderCell("Image");
column.ColumnItemsTemplate(t => t.ImageFilePath(defaultImageFilePath: string.Empty, fitImages: false));
});
columns.AddColumn(column =>
{
column.PropertyName<ImageRecord>(x => x.Name);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(3);
column.Width(2);
column.HeaderCell("Name");
});
})
.MainTableEvents(events =>
{
events.DataSourceIsEmpty(message: "There is no data available to display.");
})
.Export(export =>
{
export.ToExcel();
export.ToXml();
})
.Generate(data => data.AsPdfFile(TestUtils.GetOutputFileName()));
}
}
}