Unable to set inherit zoom for existing links

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);
        }
    }

@kranthireddyr

Thanks for contacting support.

Would you please share a sample PDF document with us. We will test the scenario in our environment and address it accordingly.

Hi @asad.ali

please find the sample document sample.pdf (27.0 KB)

We are awaiting for the solution, which can make easier to update Links and bookmarks

@kranthireddyr

Thanks for sharing sample PDF document.

We have tried to set inherit zoom for links and bookmarks by modifying your code snippet as following but did not get much success. Hence, we have logged an issue as PDFNET-45216 in our issue tracking system. We will further investigate the logged issue in details and keep you posted with the status of its correction. Please be patient and spare us little time. An output generated after trying modified code, is also attached.

....................
....................
string linkType = link.Action.ToString();
                if (linkType == "Aspose.Pdf.Annotations.GoToAction")
                {
                    double[] Dest = new double[3];
                    Dest[0] = 0;//left
                    Dest[1] = 0;//top
                    Dest[2] = 0;//pagenumber

                    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;
                            Dest[0] = xyzdest.Left;
                            Dest[2] = xyzdest.PageNumber;
                        }
                        else if (TypeDest.Name == "FitBHExplicitDestination")
                        {
                            var xyzdest = (goToAction.Destination as FitBHExplicitDestination);
                            Dest[1] = xyzdest.Top;
                            Dest[2] = xyzdest.PageNumber;
                        }
                        else if (TypeDest.Name == "FitHExplicitDestination")
                        {
                            var xyzdest = (goToAction.Destination as FitHExplicitDestination);
                            Dest[1] = xyzdest.Top;
                            Dest[2] = xyzdest.PageNumber;
                        }
                        else if (TypeDest.Name == "FitRExplicitDestination")
                        {
                            var xyzdest = (goToAction.Destination as FitRExplicitDestination);
                            Dest[1] = xyzdest.Top;
                            Dest[2] = xyzdest.PageNumber;
                            Dest[0] = xyzdest.Left;
                        }

                        var dest = (goToAction.Destination as ExplicitDestination);
                        int pageNo = dest.PageNumber;
                        if (pageNo == 0)
                            pageNo = 1;

                        Page destpage = document.Pages[pageNo];
                        link.Action = new GoToAction(new XYZExplicitDestination((int)Dest[2], Dest[1], Dest[0], 0));
                    }
                }
....................
....................

sampleinheritzoom_out.pdf (25.3 KB)

We are sorry for this inconvenience.

@asad.ali

Thanks for the sharing the issue details.

might nothing was updated in sampleinheritzoom_out.pdf

Is their any other way to set only Inherit zoom for existing LinkAnnotation & Outlines objects
without verifying type and creating new link like…

//Is their any solution like below
foreach (Page aPage in ddocument.Pages)
{
      foreach (Annotation item in aPage.Annotations)
       {
         item.ExplicitDestinationType = ExplicitDestinationType.XYZ;
         item.Destination.PageNumert=1;
         item.Destination.Top = 0;
       }
}
&&

 foreach (OutlineItemCollection bookmark in ddocument.Outlines)
      {
         bookmark.PageDisplay= "XYZ";
         bookmark.Title= "Sample Bookmark";
         bookmark.PageNumber = 1;
         bookmark.Action=  "GoTo";
      }
  ddocument.save(PdfFilepath);

and not able to update existing Annotations && Bookmarks by updating the existing objects…

@kranthireddyr

Thanks for your feedback.

We have updated the issue details and logged your additional inquiry with it as well. We will further check the feasibility of how the issue can be resolved and keep you posted with the updates in this regard. Please spare us little time.

We are sorry for the inconvenience.

@asad.ali

Hi Team,

          Is there any update regarding this issue.

your regards,
Babu.k

@Babu007

We are afraid that the earlier logged ticket has not been yet resolved due to other issues in the queue. Nevertheless, your concerns have been recorded as well and we will surely inform you as soon as we make some progress towards ticket resolution. Please spare us some time.

We are sorry for the inconvenience.

Is there any progress on this issue ?

@Agati

Regretfully, no updates are available at the moment as the ticket was not fully investigated. We will inform you once we have some news about its resolution or ETA. We apologize for your inconvenience.