Hi,
Just want to ask if there is a feature of DynamicPDF where it will automatically create the table of contents?
For now I am using this code.
public void BuildPDF()
{
IList<KeyValuePair<string, string>> tableOfContentList = new List<KeyValuePair<string, string>>();
Document document = new Document();
#region -- Front Page Creation --
//Page frontPage = new FrontPageContent().CreateFrontPage(imagePath);
//document.Pages.Add(frontPage);
#endregion
// total Number of page and page Description: example ("2", "Comparison of Inbound Exam Results with Outbound Exam Results")
tableOfContentList.Add(new KeyValuePair<string, string>("2", "Comparison of Inbound Exam Results with Outbound Exam Results"));
tableOfContentList.Add(new KeyValuePair<string, string>("1", "Inbound Exam"));
tableOfContentList.Add(new KeyValuePair<string, string>("1", "Inbound Exam Summary"));
tableOfContentList.Add(new KeyValuePair<string, string>("1", "Outbound Exam"));
tableOfContentList.Add(new KeyValuePair<string, string>("1", "Outbound Exam Summary"));
tableOfContentList.Add(new KeyValuePair<string, string>("1", "Accounting"));
#region -- Table of Contents Creation --
Page tableOfContentPage = BuildTableOfContent(
"ON-BOARDING PACKET TABLE OF CONTENTS",
tableOfContentList);
document.Pages.Add(tableOfContentPage);
#endregion
#region -- Page 4 Creation --
//Page page4 = new Page();
//document.Pages.Add(frontPage);
#endregion
document.Draw(@"C:\Junk\Test Files\TableOfContents.pdf");
}
public Page BuildTableOfContent(string title, IList<KeyValuePair<string, string>> dataList)
{
Page page = new Page(PageSize.Letter);
Label header = new Label(title, 0, 0, 512, 14, Font.HelveticaBold, 15,
TextAlign.Center);
header.TextColor = new RgbColor(38, 53, 72);
page.Elements.Add(header);
int count = 3; // Start of paging for the dynamic pages
int x = 50;
Table2 table = new Table2(0, 40, 512, 600);
table.Columns.Add(490);
table.Columns.Add(22);
table.CellDefault.Border.Width = 0.001f;
table.CellDefault.VAlign = VAlign.Center;
foreach (KeyValuePair<string, string> list in dataList)
{
Row2 row = table.Rows.Add(25);
row.CellDefault.Align = TextAlign.Left;
row.CellDefault.VAlign = VAlign.Center;
row.CellDefault.Border.Top.LineStyle = LineStyle.None;
row.CellDefault.Border.Left.LineStyle = LineStyle.None;
row.CellDefault.Border.Right.LineStyle = LineStyle.None;
row.CellDefault.Border.Width = 0.001f;
row.CellDefault.Padding.Left = 5;
row.CellDefault.Padding.Right = 5;
row.CellDefault.FontSize = 10;
Cell2 cell = row.Cells.Add("");
Group group = new Group();
FormattedTextAreaStyle style = new FormattedTextAreaStyle(FontFamily.Helvetica, 10, true);
FormattedTextArea area = new FormattedTextArea(list.Value, 0, 2, 502, 20, style);
area.VAlign = VAlign.Center;
group.Add(area);
cell.Element = group;
row.Cells.Add(count.ToString());
count += Convert.ToInt32(list.Key);
x = x + 20;
}
page.Elements.Add(table);
return page;
}
If there is a more faster way without doing this one?
Thank you,
Leo