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/pdf/net/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).
Hi There,
Thanks for contacting support.
I have tried the same code snippet given over the first link which you have shared, using latest version of the API and did not notice the issue which you have mentioned. The generated output by the code had link inside it pointing to a URL. Nevertheless, please check following code snippet which I have tried to add link inside PDF document.
Document doc = new Document();
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");
page.Annotations.Add(link);
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;
page.Annotations.Add(textAnnotation);
doc.Save(dataDir + "AddHyperlink_out.pdf");
I have also attached an output, generated by above code, for your reference.
edamron:
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.
Best Regards,
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):
https://cl.ly/2J1a0H0D2i3S
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.
Hi,