Can you give an example on how to use GoToAction(Document doc, string name).
My need is to navigate user on clicking on the text to it’s existence on the document in other pages. So what name should need to pass in GoToAction?
And also how can I add GoToAction on TextFragment?
using Aspose.Pdf.Annotations;
using Aspose.Pdf;
using Aspose.Pdf.Text;
namespace ConsoleApp1
{
internal class Program
{
static void Main()
{
// Load the PDF file
Document doc = new(@"Sample-Document.pdf");
Page page1 = doc.Pages[1];
TextFragmentAbsorber textFragmentAbsorber1 = new("Some text 1");
textFragmentAbsorber1.Visit(page1);
var tf1 = textFragmentAbsorber1.TextFragments.First();
var linkAnnotation = new LinkAnnotation(page1, tf1.Rectangle);
Page page2 = doc.Pages[2];
TextFragmentAbsorber textFragmentAbsorber2 = new("Some text 2");
textFragmentAbsorber2.Visit(page2);
var tf2 = textFragmentAbsorber2.TextFragments.First();
// Create the variable to set the zoom factor of the target page
double zoom = 2.5;
// Create GoToAction instance
GoToAction action = new(page2)
{
// Go to 2 page
Destination = new XYZExplicitDestination(page2, tf2.Rectangle.LLX, tf2.Rectangle.URY, zoom)
};
linkAnnotation.Action = action;
page1.Annotations.Add(linkAnnotation);
// Save updated document
doc.Save("goto2page_out.pdf");
}
}
}
Thank you for your quick support. Can you please also tell, how to accomplish same you did in above code using GoToAction(Document doc, string name).
Because We are merging two pdfs into one. First pdf contains content with keywords and second pdf contains keyword’s stats like how many keywords found on which page number.
While making stats pdf we need to add GoToAction by name and then in content pdf also we should use same to make those keywords focused when we click on stats keyword’s page number.
For reference attaching image.
Hi @andriy.andrukhovski
Thank you for your quick response. It is very helpful.
As per our requirement, page numbers with keywords page should appear first and then the complete document. So to do same when I switched merging code. The navigation stopped.
I only did following change:
Hi @andriy.andrukhovski
Thank you for your support. Figure out solution by using insert in the beginning of the document.
I used following line of code: