I have two different methods for getting a local hyperlink to a different page in the PDF. Method 1 works but I can’t change the position of the hyperlink. It always appears in the same place. Method 2 doesn’t work, the hyperlink looks OK but doesn’t work when you click. How do you get a working local hyperlink where you can set its absolute position to anywhere on the page please?
// Method 1 (link works but position never changes)
var pdfDocument = new Aspose.Pdf.Document(pdfToRead);
var firstPage = pdfDocument.Pages.First();
var linkSegment = new TextSegment("click to go to page 8");
var link = new LocalHyperlink { TargetPageNumber = 8 };
linkSegment.Hyperlink = link;
TextState textState = GetDefaultTextState();
linkSegment.TextState = textState;
var textFragment = new TextFragment();
textFragment.Segments.Add(linkSegment);
textFragment.Position.XIndent = 200; // has no affect
textFragment.Position.YIndent = 300; // has no affect
firstPage.Paragraphs.Add(textFragment);
pdfDocument.Save(pdfToWrite);
// Method 2 - Position works, hyperlink doesn't work (does nothing on click)
var pdfDocument = new Aspose.Pdf.Document(pdfToRead);
var firstPage = pdfDocument.Pages.First();
var linkSegment = new TextSegment("click to go to page 8");
var link = new LocalHyperlink { TargetPageNumber = 8 };
linkSegment.Hyperlink = link; // doesn't work
TextState textState = GetDefaultTextState();
linkSegment.TextState = textState;
var textFragment = new TextFragment();
textFragment.Segments.Add(linkSegment);
var textParagraph = new TextParagraph
{
Position = new Position(200, 200) // works
};
textParagraph.AppendLine(textFragment);
TextBuilder textBuilder = new TextBuilder(firstPage);
textBuilder.AppendParagraph(textParagraph);
pdfDocument.Save(pdfToWrite);