Hyperlink Destination Not Saved

I have tried both using both a LinkAnnotation (per “Working with Actions in PDF|Aspose.PDF for .NET”) and PdfContentEditor (per “PdfContentEditor Class|Aspose.PDF for .NET”) 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).


I’m currently using version 11.1.1. I’m not sure what the current version is (never imagined it would be so hard to find something so simple).

Thoughts or suggestions?

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):

Image 2017-04-21 at 11.23.1...


Only two differences remain between your sample code and my production code:
1 - my document comes into my method via a byte[] (I call pdfBytes), which is used to instantiate my Document object:

var document = new Aspose.Pdf.Document(new MemoryStream(pdfBytes));

2 - From there, once I add the hyperlink using your code, I return it to the calling method by streaming it back out via a byte[]:

using (var outputStream = new MemoryStream())
{
document.Save(outputStream);
return outputStream.ToArray();
}

I can start messing with these to see if either of these two operations are messing with the document. Do you know of any reason why streaming the doc from, or back to, a byte[] might cause my issue?

Thank you.

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.


Investigating…

Hi,


Thanks for sharing the details.

From your above statement, it appears that you are facing issue while manipulating an existing PDF file and in our earlier attempt, we tested the scenario while creating a document from scratch. If the problem still persists, can you please share the document causing problem and a sample project, so that we can further investigate the issue in our environment. We are sorry for this inconvenience.