LocalHyperlink and Target Page Number

Where are evaluating Aspose.PDF. We have found and or confirmed several issues with Footnotes and Endnote that are listed in your support page which hopefully will be addressed soon.
We have another scenario where we are creating a PDF using Aspose.PDF DOM. This is accomplished by looping through some custom hierarchical objects and create various Tables etc. During this process references are encounter that are somewhat like End Notes. When a reference is encountered, a Text Fragment is created, with a Text Segment and that Segment gets a LocalHyperLink created. The actual reference Text will be listed on the last page. How can I set the LocalHyperLink’s TargetPageNumber when I do not know what the last page number will be? Any help greatly appreciated.

@Jacob77

Thanks for contacting support.

Before setting the TargetPageNumber, please call ProcessParagraphs() method of Document object. This way you will get correct page count of PDF before it is saved. In case you still face any issue, please share your sample code snippet along with sample PDF document, so that we can test the scenario in our environment and address it accordingly.

Thanks. Can you provide an example? I 'll try to get a sample together as our current application is rather large.
Thanks again.

@Jacob77

Thanks for writing back.

Please check following code snippet which demonstrates a basic use of ProcessParagraphs() method, in order to get last page number and add a hyperlink for it. For your reference, an output is also attached.

Document doc = new Document();
var page = doc.Pages.Add();
Table table = new Table();

Row Header = new Row();
Header.Cells.Add("header");
Header.Cells.Add("header");
TextFragment tf = new TextFragment("New Line");
Header.Cells[1].Paragraphs.Add(tf);
table.Rows.Add(Header);
            
Row r = new Row();
r.Cells.Add("Cell");
r.Cells.Add("Cell");
int i = 0;
while (i < 180)
{
 table.Rows.Add(r);
 i++;
}
table.RepeatingRowsCount = 1;
page.Paragraphs.Add(table);

int countbefore = doc.Pages.Count;
doc.ProcessParagraphs();
int countafter = doc.Pages.Count;

Console.WriteLine($@"Before ProcessParagraph => {countbefore} and After ProcessParagraph => {countafter}");

TextFragment t = new TextFragment("Goto Last Page");
t.TextState.ForegroundColor = Color.Blue;
t.TextState.Underline = true;
LocalHyperlink link = new LocalHyperlink();
link.TargetPageNumber = doc.Pages.Count;
t.Hyperlink = link;
HeaderFooter footer = new HeaderFooter();
footer.Paragraphs.Add(t);
doc.Pages[1].Footer = footer;

doc.Save(dataDir + "PageBreakTable.pdf");

PageBreakTable.pdf (5.1 KB)

In case of any further assistance, please feel free to let us know.

Thanks for the example. Look like I may not be able to do what is required. Please look at my example document and code example.
Thanks again for your help and any suggestions you may have.AsposeLocalHyperLinkExample.pdf (117.8 KB)
Example.zip (18.3 KB)

@Jacob77

Thanks for sharing sample project and PDF document.

We are looking into the scenario and will get back to you shortly.

@Jacob77

Thanks for your patience.

Please check attached sample console application, which will generate PDF file as per your requirements, where hyperlinks will point to respective note at the last page. For your reference, a sample output PDF is also attached, which was generated by attached sample project.

AsposeLocalHyperLinkExample.pdf (114.4 KB)
LocalHyperlinkSampleProject.zip (24.0 KB)

In case of any further assistance, please feel free to let us know.

Thanks for the example. Very helpful. Although found that if a table row is a header row and has a link to a LocalHyperLink and the table breaks across pages the Hyperlink in the Header of the the Table on the second page does not work. See Table named ‘DNGXWRC’
Attached PDF and sample code.
Thanks again.AsposeLocalHyperLinkExample.pdf (119.2 KB)
ConsoleApplication.zip (17.2 KB)

@Jacob77

Thanks for writing back.

We were also able to notice the issue which you have mentioned and for the sake of correction, we have logged it as PDFNET-43640 in our issue tracking system. We will further look into the details of the issue and keep you informed with the status of its resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.