Dear Team
We have hyperlinks on page with goto page action. However, we are not able to handle destination and actions for all links in same way. Please find program written below to set all hyperlinks to inheritzoom. For 4 links, we are accessing destination using a.Destination and for one link we are accessing using a.Action.
public static void LinkInheritZoom(String sourcePath, String OutputPath)
{
Document document = new Document(sourcePath);
if (document.Pages.Count != 0)
{
var editor = new PdfContentEditor(document);
foreach (Aspose.Pdf.Page page in document.Pages)
{
AnnotationSelector selector = new AnnotationSelector(new Aspose.Pdf.Annotations.LinkAnnotation(page, Aspose.Pdf.Rectangle.Trivial));
page.Accept(selector);
IList<Annotation> list = selector.Selected;
foreach (LinkAnnotation a in list)
{
string URL = string.Empty;
IAppointment dest = a.Destination;
if (a.Action != null || dest != null)
{
if (a.Action != null)
{
int pageNo = ((Aspose.Pdf.Annotations.ExplicitDestination)((Aspose.Pdf.Annotations.GoToAction)a.Action).Destination).PageNumber;
XYZExplicitDestination xyznew = new XYZExplicitDestination(pageNo, 0, document.Pages[pageNo].PageInfo.Height, 0.0);
GoToAction gta = (Aspose.Pdf.Annotations.GoToAction)a.Action;
gta.Destination = xyznew;
}
else if (a.Destination!=null)
{
int pageNo = ((Aspose.Pdf.Annotations.ExplicitDestination)(a.Destination)).PageNumber;
XYZExplicitDestination xyznew = new XYZExplicitDestination(pageNo, 0, document.Pages[pageNo].PageInfo.Height, 0.0);
a.Destination = xyznew;
}
}
}
}
document.Save(OutputPath);
}
}
Our question 1 is, Whether we are going in correct way to handle it?
Question 2 is, Why Aspose is recognizing them as different link? Is there any particular condition in which this situation occur?
Please find document used for this example
Page 2 test.pdf (491.3 KB)