forked from VahidN/iTextSharp.LGPLv2.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PdfPTableTests.cs
106 lines (90 loc) · 3.13 KB
/
PdfPTableTests.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
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace iTextSharp.LGPLv2.Core.FunctionalTests
{
[TestClass]
public class PdfPTableTests
{
[TestMethod]
public void Verify_MultiColumn_Report_CanBe_Processed()
{
var pdfFilePath = TestUtils.GetOutputFileName();
var fileStream = new FileStream(pdfFilePath, FileMode.Create);
var pdfDoc = new Document(PageSize.A4);
var pdfWriter = PdfWriter.GetInstance(pdfDoc, fileStream);
pdfDoc.AddAuthor(TestUtils.Author);
pdfDoc.Open();
var table1 = new PdfPTable(1)
{
WidthPercentage = 100f,
HeaderRows = 3,
FooterRows = 1
};
//header row
var headerCell1 = new PdfPCell(new Phrase("header row-1"));
table1.AddCell(headerCell1);
var headerCell2 = new PdfPCell(new Phrase("header row-2"));
table1.AddCell(headerCell2);
//footer row
var footerCell = new PdfPCell(new Phrase(" footer "));
table1.AddCell(footerCell);
//adding some rows
for (int i = 0; i < 400; i++)
{
var rowCell = new PdfPCell(new Phrase(i.ToString()));
table1.AddCell(rowCell);
}
table1.SkipFirstHeader = true;
// wrapping table1 in multiple columns
ColumnText ct = new ColumnText(pdfWriter.DirectContent)
{
RunDirection = PdfWriter.RUN_DIRECTION_RTL
};
ct.AddElement(table1);
int status = 0;
int count = 0;
int l = 0;
int columnsWidth = 100;
int columnsMargin = 7;
int columnsPerPage = 4;
int r = columnsWidth;
bool isRtl = true;
// render the column as long as it has content
while (ColumnText.HasMoreText(status))
{
if (isRtl)
{
ct.SetSimpleColumn(
pdfDoc.Right - l, pdfDoc.Bottom,
pdfDoc.Right - r, pdfDoc.Top
);
}
else
{
ct.SetSimpleColumn(
pdfDoc.Left + l, pdfDoc.Bottom,
pdfDoc.Left + r, pdfDoc.Top
);
}
var delta = columnsWidth + columnsMargin;
l += delta;
r += delta;
// render as much content as possible
status = ct.Go();
// go to a new page if you've reached the last column
if (++count > columnsPerPage)
{
count = 0;
l = 0;
r = columnsWidth;
pdfDoc.NewPage();
}
}
pdfDoc.Close();
fileStream.Dispose();
TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
}
}
}