I have tried both using both a LinkAnnotation (per “https://docs.aspose.com/display/pdfnet/Add+and+Get+Hyperlink”) and PdfContentEditor (per “https://docs.aspose.com/display/pdfnet/Working+with+the+PdfContentEditor+class”) to create a hyperlink on a PDF (to a simple site like “www.google.com”). In both cases, the target URI seems to end up pointing to the document itself, even though I’ve triple-checked my code, and it’s identical to the code shown on the pages above (sans the URL).
Document doc = new Document();<o:p></o:p>
Page page = doc.Pages.Add();
LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 300, 300));
Border border = new Border(link);
border.Width = 0;
link.Border = border;
link.Action = new GoToURIAction("www.aspose.com");
FreeTextAnnotation textAnnotation = new FreeTextAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 300, 300), new DefaultAppearance(Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"), 10, System.Drawing.Color.Blue));
textAnnotation.Contents = "Link to Aspose website";
textAnnotation.Border = border;
doc.Save(dataDir + "AddHyperlink_out.pdf");
I have also attached an output, generated by above code, for your reference.
I'm currently using version 11.1.1. I'm not sure what the current version is
Latest version of the API is 17.4.0 and can be downloaded from Downloads section on the Aspose Website. Please try using latest version of the API as it is recommended and in case you still face any issue, please share sample code snippet which you are trying. This will help us understanding the scenario precisely.
Very odd…when I paste your code into mine, my link ends up corrupted. Here’s a screen shot of what the link points to (shown in the tooltip):
I just found out that if I create a document from scratch inside the method, and write it back out, again inside the method, it works just fine. There something about the document I’m streaming in via byte that is causing the issue.