C1PdfViewer go to named destination

Posted by: daniel.erdei on 1 December 2021, 9:26 am EST

    • Post Options:
    • Link

    Posted 1 December 2021, 9:26 am EST

    We are currently testing various PDF-Viewers from different software manufacturers to embed in our software application (C# / WPF).

    After our functional tests with the trial version, we came to the conclusion that your PDF-Viewer suits our needs the best. Especially when it comes to scrolling and navigating through large documents on remote servers that do not have any dedicated graphics card installed, the performance of your PDF-viewer is outstanding and scrolling works very fluently compared to other PDF-viewers.

    However, in contrast to other PDF-Viewers, we have one big showstopper by using the ComponentOne PDF-Viewer:

    We cannot scroll to Named Destinations in PDF documents.

    Linking to headings, that are labeled with named destinations, in other PDF documents is a very crucial process for us. In other words, our goal is that a hyperlink inside of document A does not open only document B, but opens it and jumps to on a specific heading (=named destination).

    Currently the PDF-viewer does only provide the “GoToBookmark” method to scroll to a specific text/bookmark. The reason why we cannot use this function is because we can only pass a text (string) into that function. In our PDFs there could possibly be multiple headings that have the exact same title. By using GoToBookmark we would always result in scrolling to the first heading; but we do not have any chance to jump to the second, third … one.

    In addition, but not as important, it would be nice if we could fetch all the named destinations of a pdf, like we already can with bookmarks.

    If this Prio-A problem cannot be fixed, unfortunately we have to exclude ComponentOne from our selection of PDF-Viewers.

  • Posted 2 December 2021, 8:43 am EST

    Hi,

    We suggests you to use FlexViewer instead PdfViewer. Because PdfViewer is in maintenance mode and not under active development.

    In FlexViewer, you can navigate to the Bookmarks through NavigateToOutlineNode.

    For multi-bookmarks navigation of same heading, you can create a simple Extension. (see code snippet)

    
    public static class FlexViewerExtension
        {
            private static OutlineNode currentOutline;
            public static void GoToBookmark(this C1FlexViewer flexViewer, string bookmark)
            {
                var pdfDoc = (C1PdfDocumentSource)flexViewer.DocumentSource;
    
                currentOutline = GetOutlineNode(pdfDoc.Document.Outlines, bookmark);
                if (currentOutline != null)
                    flexViewer.Pane.NavigateToOutlineNode(currentOutline);
            }
    
            public static OutlineNode GetOutlineNode(OutlineNodeCollection outlines, string bookmark)
            {
                foreach(var outline in outlines)
                {
                    // continue if outline is focused
                    if (outline == currentOutline)
                        continue;
    
                    if (outline.Caption == bookmark)
                        return outline;
    
                    if (outline.Children.Count == 0)
                        continue;
    
                    if (GetOutlineNode(outline.Children, bookmark) == null)
                        continue;
                }
                return null;
            }
        }
    
    

    Please refer the attached sample for the same : FlexViewerNavigation.zip

    Best Regards,

    Nitin

  • Posted 3 December 2021, 4:43 am EST

    Hello Nitin,

    thanks a lot for your advice to try C1FlexViewer and the provided sample.

    I have two questions regarding C1FlexViewer:

    • "

    • "As far as I see, navigating to bookmarks with “real” named destinations is also not possible with C1FlexViewer, is it? Specifically, I do not speak about jumping to a bookmark with a certain caption (text/string) but to jump to a bookmark with a specific unique key, also known as Named Destination (see for example https://www.evermap.com/Tutorial_ABM_Destinations.asp). I did not find any way to get all or jump to a specific named destination from a pdf using C1FlexViewer. Other PDF-Viewer provide this functionality which is very crucial for our processes. "

    • “How can I listen to an event when a user clicks on a hyperlink in a PDF and get the URL of the clicked link via code? The C1PdfViewer has an event called RequestNavigate that works perfectly fine. I can listen to that event and when it gets fired I can get the URL out of the link. I did not find any event to accomplish that with C1FlexViewer, how could i do that?”

    "

  • Posted 3 December 2021, 10:27 am EST

    Hi,

    Thanks for the reference,

    1. We’re discussing this feature with the development team, We’ll get back to you once we have any update. [Internal Track Id - C1XAML-28517]

    2. In order to notify on hyperlink click, you need to handle FlexViewerPane’s HyperlinkClicked event as :

    
    private void FlexViewer_Loaded(object sender, RoutedEventArgs e)
    {
         flexViewer.Pane.HyperlinkClicked += Pane_HyperlinkClicked;
    }
    
    private void Pane_HyperlinkClicked(object sender, C1.WPF.FlexViewer.HyperlinkClickedEventArgs e)
    {
         var url = (e.Hyperlink.LinkTarget as C1LinkTargetFile).FileName;
         Debug.WriteLine(url);
    }
    
    

    Please refer the attached sample for the same : FlexViewerHyperlink.zip

    Best Regards,

    Nitin

  • Posted 6 December 2021, 2:54 am EST

    Hello,

    thanks a lot for the provided hyperlink sample and keeping me up to date about my feature request.

    Best regards,

    Andreas Salminger

  • Posted 9 December 2021, 3:09 am EST

    Hello,

    can you give us an estimated date until when you can tell us if our feature request with named destinations is possible or not? This feature is a very important purchase criterion for us and therefore we would like to know as soon as possible.

    I have got one further question regarding C1PdfViewer (not C1FlexViewer):

    • "* “Is there any toolbar function (or API to use in code) to rotate (all) pages in a PDF document clock-wise? (Note: The PDF does not need to save the rotated pages)”

    • “Our customers often scan some documents and some of them are rotated in the wrong way (portrait vs. landscape). In our research with other PDF viewer controls, we found out that they are able to rotate pages directly inside their PDF viewers (Adobe Acrobat and Google Chrome do also support this). Is that also possible with C1PdfViewer?”

      "

  • Posted 9 December 2021, 8:38 am EST

    Hello,

    Thanks for your patience.

    1. Could you please provide the Pdf file consists named Destination. So, that we can do the needful.

    2. C1PdfViewer doesn’t have rotate feature. However, you can manually rotate pages(you can get it from C1ListViewerItem’s template) through RotateTransform as:

    
    void Rotate()
            {
                var list = pdfViewer.Template.FindName("PageList", pdfViewer) as C1ListViewer;
                for (int i = 0; i < list.Items.Count; i++)
                {
                    var item = list.ItemContainerGenerator.ContainerFromIndex(i);
                    if (item != null)
                    {
                        C1ListViewerItem listItem = (C1ListViewerItem)(item);
                        var child = VisualTreeHelper.GetChild(listItem, 0);
                        if (child is Border)
                        {
                            var bdr = (Border)child;
                            RotateTransform rotate = new RotateTransform(_angle, bdr.ActualWidth / 2, bdr.ActualHeight / 2);
                            bdr.RenderTransform = rotate;                        
                        }
                    }
                }
            }
    
    

    Please refer the attached sample for the same : PdfRotate.zip

    Best Regards,

    Nitin

  • Posted 9 December 2021, 9:16 am EST

    Hello Nitin,

    thank you very much for your help regarding rotating pages in a PDF document.

    I have provided you a sample PDF with named destinations.

    Each number, that is a prime number, has a named destination with key “Prime{number}” (for example “Prime2” or “Prime17”).

    With Adobe Acrobat Reader, Google Chrome and other PDF viewer controls for WPF I am now able to open this PDF document and jump a specific named destination.

    Acrobat Reader

    • "* “Windows Run (Windows+R)”

    • “acrord32.exe /A “nameddest=Prime17” “C:\path\to\sample\Test_NamedDest.pdf””

    • “Document opens on page 16”

    "

  • Posted 9 December 2021, 9:19 am EST

    Sorry, the upload did not work.

    Here is the sample pdf file: Test_NamedDest.zip

  • Posted 10 December 2021, 12:30 am EST

    Hi,

    Thanks for acknowledging and providing the pdf file.

    We have forwarded it to the devs and will get back to you once we have any update.

    Regards,

    Nitin

  • Posted 10 December 2021, 3:16 am EST

    Hello Daniel,

    The named destinations comes in C1PdfViewer bookmarks and C1FlexViewer outlines.

    We can navigate to them using their caption/title.

    JFYI, the caption/title in the outlines/bookmarks is basically the unique id.

    We have attached the modified sample, where you can enter the caption/title/namedDestination into the TextBox and navigate to the destination by clicking on Navigate button : FlexViewerPageNavigation_Mod.zip

    Best Regards,

    Nitin

  • Posted 10 December 2021, 5:34 am EST

    Hello Nitin,

    we are aware that we can navigate to bookmarks/outlines by their caption/title.

    However, bookmarks and named destinations are not the same. Not every named destination must be a bookmark. And it is also not true, that a bookmark title is a unique ID, because there may be multiple bookmarks with the same title.

    For clarification, I have attached a new sample with two named destinations that are not bookmarks (they have just a bigger font size to mark them; details regarding the sample PDF see below).

    Our problem with navigating by caption/title, as stated in my original post, is that our PDFs can have multiple destinations with the same caption. As you compare the outlines by using a String Equals, I can only jump to the first outline with that specific title; but i do not have any chance to jump to the second, third, fourth … one with the same title.

    Furthermore, I cannot use outlines in the provided sample PDF, because the named destinations are simple PDF paragraphs, and not bookmarks/outlines. Therefore, if I try to get the outlines from C1FlexViewer, the result is empty.

    Sample PDF

    • "* “first page: two links to the named destinations”

    • “second page: a paragraph with caption Test an named destination Test01

    • “third page: a paragraph also with caption Test but named destination Test02

    Acrobat Reader

    • “[li]Open PDF at first paragraph (named destination) with caption Test:

      acrord32.exe /A “nameddest=Test01” “C:\path\to\named-dest-output.pdf””

    • “Open PDF at second paragraph (named destination) with caption Test:

      acrord32.exe /A “nameddest=Test02” “C:\path\to\named-dest-output.pdf””

      "

    How could I archieve this by using C1FlexViewer?

    Let me know, if you have any further questions.

    Sample PDF: named-dest-output.zip

    Kind Regards,

    Andreas

  • Posted 13 December 2021, 1:57 am EST

    Hi,

    Thanks for the pdf sample.

    We didn’t get outlines in this Pdf sample, Named destination is working without any outline i.e., there’s no outlines available in pdf but named destination still working.

    We have forwarded the pdf to the development team and will get in touch with you whenever we get update from the devs.

    Regards,

    Nitin

  • Posted 20 December 2021, 6:12 am EST

    Hi,

    could you please provide us with an example how you jump to named destinations when there are no outlines available (as in my sample pdf)

    Regards,

    Andreas

  • Posted 20 December 2021, 6:25 am EST

    Hello,

    Apologize for the miscommunication.

    We actually meant to say, that there’s no outline available in your provided Pdf and we can navigate namedDestination through Acrobat Reader like you are navigating.

    But we’re unable to navigate it into C1FlexViewer. That’s why we have escalated this issue to the development team. They are working on it and we will inform you whenever we get any update from the devs.

    Regards,

    Nitin

  • Posted 21 December 2021, 7:39 am EST

    Hello Andreas,

    Thanks for your patience.

    You can navigate through NamedDestination in C1FlexViewer using GrapeCity.Documents.Pdf . It supports named destination. You can navigate as : (see code snippet)

    
    GcPdfDocument doc = new GcPdfDocument();
    var fs = new FileStream(pdfDocumentSource.DocumentLocation, FileMode.Open, FileAccess.Read);
    doc.Load(fs);
    string name = doc.NamedDestinations.Keys.First();
    DestinationXYZ nd = doc.NamedDestinations[name] as DestinationXYZ;
    var tp = new C1LinkTargetPage(null, nd.Page.Index, new Rect(nd.Left ?? 0, nd.Top ?? 0, 0, 0));
    C1.WPF.Document.OutlineNode node = new C1.WPF.Document.OutlineNode() { LinkTarget = tp };
    fv.Pane.NavigateToOutlineNode(node);
    
    

    JFYI, C1FlexViewer doesn’t support named destination directly. You can add GrapeCity.Documents.Pdf through nuget and need to purchase license for GCDocuments too, in order to use GrapeCity.Documents.Pdf.

    You can refer Grapecity.Documents.Pdf here : https://www.grapecity.com/documents-api-pdf

    Please refer the attached modified sample for the same : FlexViewerPageNavigation_Mod2.zip

    Best Regards,

    Nitin

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels