Cannot add local hyperlink to the existing document

Hi there,

This topic can be considered as continuation of these previous two topics: “Attach inner-document links to existing text” and “Remove visible rectangular border when adding local link using Facades”.

I’m using Aspose.Pdf for .NET, the latest version. I have the next situation. My software obtains an already created PDF document with text on input. It need to modify this document by transforming specified text string onto local links.

At this time I tried to do this using “Create hyperlink to pages in same PDF” manual. In the source code which is present below I’m creating a new dummy PDF with two pages and primitive text on the first stage. And on the second stage I’m trying to modify text on the first page by adding a local hyperlink to it. But in result, unfortunately, local hyperlink is absent in the output PDF. Is this a bug or I’m doing something wrong?

//create dummy PDF

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Page page1 = doc.Pages.Add();
Aspose.Pdf.Text.TextFragment text = new Aspose.Pdf.Text.TextFragment(“link to page 2”);
page1.Paragraphs.Add(text);
Page page2 = doc.Pages.Add();
page2.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment(“this is page 2”));
doc.Save(SharedData.FilesOutputFolder + “input.pdf”);

//open existing PDF and find required text
Aspose.Pdf.Document newDoc = new Aspose.Pdf.Document(SharedData.FilesOutputFolder + “input.pdf”);
Aspose.Pdf.Page firstPage = newDoc.Pages[1];
Aspose.Pdf.Text.TextFragmentAbsorber absorber = new TextFragmentAbsorber();
firstPage.Accept(absorber);
Aspose.Pdf.Text.TextFragmentCollection collection = absorber.TextFragments;
Aspose.Pdf.Text.TextFragment oneFragment = collection[1];

//add link into existing PDF
Aspose.Pdf.LocalHyperlink link = new Aspose.Pdf.LocalHyperlink();
link.TargetPageNumber = 2;
oneFragment.Hyperlink = link;
newDoc.Save(SharedData.FilesOutputFolder + “output.pdf”);</em>

“Input.pdf” and “output.pdf” are attached.

Thanks in advance.

With best regards,
Denis Gvardionov

Hi Denis,


Thanks for your inquiry. In your referenced post we have noticed that CreateLocalLink() add a rectangle around the link and already logged an issue PDFNEWNET-39018 for further investigation and resolution.

Moreover, regarding use of Hyperlink property of TextFragment. We have also noticed that it is not working for an existing TextFragment, so logged another ticket PDFNEWNET-39019 for correction. We will notify you as soon as these issues are resolved.

We are sorry for the inconvenience caused.

Best Regards,

Hello Aspose team,

Can you give me an update about these two issues (PDFNEWNET-39019 and PDFNEWNET-39018)? Four months have passed since these issues were reported. I’ve re-checked these tickets using latest Aspose.Pdf version 11.0 - they are still un-fixed. So, it is still impossible to add a correct local hyperlink into existing PDF document:

  1. using Facades: PdfContentEditor.CreateLocalLink creates visible rectangular border, which cannot be disabled;
  2. using Aspose.Pdf.LocalHyperlink: it simply is not working.

So, please, give me an estimate or at least some update.

With best regards,
Denis Gvardionov

Hi Denis,


Thanks for your patience.

As you have posted the query in normal product support forum, so issues reported earlier in this thread were logged with Low priority and they are still pending for review as the team has been busy fixing other previously reported issues. However I have raised the priority of issues to Enterprise Support and have intimated the team to investigate the issues accordingly. As soon as we have some definite updates regarding their resolution, we will let you know.

We are sorry for this delay and inconvenience.

I join this request to get this text.Hyperlink property working and will be tracking for an update.


Further to the above, I am presently on an intense learning curve with Aspose PDF. It appears to be much more than I thought when we purchased it.

I could be misunderstanding the original issue as disallowing a nicely-formatted link in text to another page in the same document. I could not access the Hyperlink property, which prevented me from using this example your Documentation supplies.

In continuing to explore, I found this other example in your documentation.

This other example works just fine for me. It creates underlined text (without a rectangle around it), and the text is a link to another page of the same document. It works as represented.

Hi Denis,


Thanks for your patience.

We have further investigated the issue PDFNEWNET-39019 reported earlier and have observed that fragment.Hyperlink property can only be used for Aspose.Pdf.Generator(please check property comment).
However if you need to add local hyperlinks, please use annotation instead of hyperlink:

[C#]

Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation
annotation =
new Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation(firstPage,
rectange);<o:p></o:p>

annotation.Action = new Pdf.InteractiveFeatures.GoToAction(new Aspose.Pdf.InteractiveFeatures.XYZExplicitDestination(newDoc.Pages[2], 0, newDoc.Pages[2].Rect.Height, 0));

firstPage.Annotations.Add(annotation);

Hi Denis,


Thanks for your patience.

We have further investigated the issue PDFNEWNET-39018 and have observed that in order to accomplish your requirement, please created a Link annotation and set its border width to 0.

[C#]

Aspose.Pdf.Document newDoc = new Aspose.Pdf.Document(“input.pdf”);<o:p></o:p>

Aspose.Pdf.Page firstPage = newDoc.Pages[1];

Aspose.Pdf.Text.TextFragmentAbsorber absorber = new TextFragmentAbsorber();

firstPage.Accept(absorber);

Aspose.Pdf.Text.TextFragmentCollection collection = absorber.TextFragments;

Aspose.Pdf.Text.TextFragment oneFragment = collection[1];

Aspose.Pdf.Rectangle rectange = oneFragment.Rectangle;

Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation link = new Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation(newDoc.Pages[1], rectange);

link.Destination = new Aspose.Pdf.InteractiveFeatures.FitExplicitDestination(newDoc.Pages[2]);

link.Border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(link);

link.Border.Width = 0;

newDoc.Pages[1].Annotations.Add(link);

newDoc.Save("output.pdf");

Hi Jeff,

Thanks for your interest in our API’s.

Please try using the code snippets suggested in my earlier post and in case you still face any issue, please feel free to contact.

This other example works just fine for me. It creates underlined text (without a rectangle around it), and the text is a link to another page of the same document. It works as represented.

This example is based on legacy Aspose.Pdf.Generator approach and we recommend using new Document Object Model (DOM) of Aspose.Pdf namespace.