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