Hi Team,
unable to set inherit zoom for existing links.
we are getting multiple issues with this code,
Please provide perfect solutions to set inherit zoom for existing links and bookmarks.
we are just trying to update the links and bookmarks(all kind of links & bookmarks) with inheritzoom level.
Please find the sample code
void updateLinks(Document doc, ref string ServiceLogref) {
foreach (Page aPage in doc.Pages)
{
foreach (Annotation item in aPage.Annotations)
{
string LinkType = item.GetType().Name;
if (LinkType == "LinkAnnotation")
{
LinkAnnotation LinkAnn = (LinkAnnotation)item;
if (LinkAnn.Action != null)
SetZoomForLink(LinkAnn, doc, ref ServiceLogref);
setLink_text_BorderColor(LinkAnn, doc, ref ServiceLogref);
}
}
}
}
void SetZoomForLink(LinkAnnotation link, Document document, ref string ServiceLogref)
{
try
{
string linkType = link.Action.ToString();
if (linkType == "Aspose.Pdf.Annotations.GoToAction")
{
double[] Dest = new double[3];
Dest[0] = 0;
Dest[1] = 0;
Dest[2] = 0;
GoToAction goToAction = (GoToAction)link.Action;
var TypeDest = goToAction.Destination.GetType();
if (TypeDest.Name != "NamedDestination")
{
if (TypeDest.Name == "XYZExplicitDestination")
{
var xyzdest = (goToAction.Destination as XYZExplicitDestination);
Dest[1] = xyzdest.Top;
}
else if (TypeDest.Name == "FitBHExplicitDestination")
{
var xyzdest = (goToAction.Destination as FitBHExplicitDestination);
Dest[1] = xyzdest.Top;
}
else if (TypeDest.Name == "FitHExplicitDestination")
{
var xyzdest = (goToAction.Destination as FitHExplicitDestination);
Dest[1] = xyzdest.Top;
}
else if (TypeDest.Name == "FitRExplicitDestination")
{
var xyzdest = (goToAction.Destination as FitRExplicitDestination);
Dest[1] = xyzdest.Top;
}
var dest = (goToAction.Destination as ExplicitDestination);
int pageNo = dest.PageNumber;
if (pageNo == 0)
pageNo = 1;
Page destpage = document.Pages[pageNo];
link.Action = new GoToAction(destpage, ExplicitDestinationType.XYZ, Dest);
}
}
else if (linkType == "Aspose.Pdf.Annotations.GoToRemoteAction")
{
GoToRemoteAction goToR = (GoToRemoteAction)link.Action;
string filename = goToR.File.Name;
var dest = (goToR.Destination as ExplicitDestination);
int pageNo = dest.PageNumber;
if (pageNo == 0)
pageNo = 1;
double[] SetTop = new double[3];
SetTop[0] = 0;
SetTop[1] = 0;
SetTop[2] = 0;
var TypeDest = goToR.Destination.GetType();
if (TypeDest.Name != "NamedDestination")
{
if (TypeDest.Name == "XYZExplicitDestination")
{
var xyzdest = (goToR.Destination as XYZExplicitDestination);
SetTop[1] = xyzdest.Top;
}
else if (TypeDest.Name == "FitBHExplicitDestination")
{
var xyzdest = (goToR.Destination as FitBHExplicitDestination);
SetTop[1] = xyzdest.Top;
}
else if (TypeDest.Name == "FitHExplicitDestination")
{
var xyzdest = (goToR.Destination as FitHExplicitDestination);
SetTop[1] = xyzdest.Top;
}
else if (TypeDest.Name == "FitRExplicitDestination")
{
var xyzdest = (goToR.Destination as FitRExplicitDestination);
SetTop[1] = xyzdest.Top;
}
GoToRemoteAction myRemoteact = new GoToRemoteAction(filename,
ExplicitDestination.CreateDestination(pageNo, ExplicitDestinationType.XYZ, SetTop));
myRemoteact.NewWindow = ExtendedBoolean.True;
link.Action = myRemoteact;
}
}
}
catch (Exception ex)
{
ServiceLogref += ex.Message;
WriteLog("Exception ==> at SetZoomForLink " + ex.Message + ex.StackTrace);
}
}