I am creating a table of contents index page in my pdf. I call this DrawText function twice, once to add the text name of the document being indexed, and the second time to draw the page number in the pdf that document is located. Each text fragment has a localhyperlink to the page in the pdf document. What I’m finding is that the localhyperlinks are duplicated from about halfway down the index page on the extreme left hand edge, but with no text.
static private void DrawText(string text, int pageNumber, Row row, int indentationLevel = 0, bool isSectionHeader = false, bool italics = false)
{
var fragment = new TextFragment(text);
fragment.Hyperlink = new LocalHyperlink()
{
TargetPageNumber = pageNumber
};
var cell = row.Cells.Add();
MarginInfo cellMargin = new MarginInfo()
{
Bottom = 1.8f,
Top = 1.8f
};
cellMargin.Left = 5 * indentationLevel;
cell.Margin = cellMargin;
cell.Paragraphs.Add(fragment);
}
The function below is what creates the pdf page for the table of contents
static private Table CreateNewTOCPage(Document pdfDocument, int numberIndexPagesAdded)
{
Page pageTOC = pdfDocument.Pages.Insert(numberIndexPagesAdded);
pageTOC.PageInfo.Margin = new MarginInfo(20, 20, 20, 20);
Table tableTOC = new Table
{
ColumnWidths = "90% 10%"
};
pageTOC.Paragraphs.Add(tableTOC);
return tableTOC;
}
and this is how the two functions are called:
var tableTOC = CreateNewTOCPage(pdfDocument, ++numberIndexPagesAdded);
foreach (var document in documents)
{
Row row = tableTOC.Rows.Add();
DrawText(document.Title, nextDocumentStartIndex, row);
DrawText(nextDocumentStartIndex.ToString(), nextDocumentStartIndex, row);
nextDocumentStartIndex += document.PageImageURLs.Count;
}