Hide visual elements in pdfNavigoator bar - get filename of document open in pdfviewer

1 Answer 265 Views
PdfViewer and PdfViewerNavigator
Claude
Top achievements
Rank 1
Iron
Veteran
Claude asked on 02 Feb 2022, 11:11 PM

1.  Is there a way to hide an element in the pdfNaviagotor bar.  I wish to hide the file open element.

2. how can i get the path of the file that is open or loaded into the pdfviewer.

3. How do I get the page number of the selected page in the viewer

4. How do I get the page count of the open file.

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Feb 2022, 03:34 PM
Hello, Claude,    

I will go straight to your questions with the following code snippet:
            //1.Hide the open file button
            this.radPdfViewerNavigator1.OpenButton.Visibility = ElementVisibility.Collapsed;

            //3. page number
            int pageIndex = int.Parse(this.radPdfViewerNavigator1.CurrentPageTextBox.Text);

            //4. total pages
            int totalPages = this.radPdfViewerNavigator1.AssociatedViewer.Document.Pages.Count;

Please have in mind that RadPdfViewer doesn't keep the file path of the loaded document in a public property once it gets loaded in the control. This is how the document is loaded when clicking the open button:

            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "PDF Files|*.pdf";
            openFileDialog.Title = "Select a PDF File";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.pdfViewerElement.LoadDocument(openFileDialog.FileName);
                this.UpdatePageCount();
            }
        public void LoadDocument(string path)
        {
            if (this.documentLoader != null)
            {                
                while (this.documentLoader.IsBusy)
                {
                    System.Threading.Thread.Sleep(50);
                    System.Windows.Forms.Application.DoEvents();
                }
            }

            this.UnloadDocument();
            this.stream = new MemoryStream(File.ReadAllBytes(path));
            this.LoadDocument(this.stream);
            this.fileName = Path.GetFileName(path);
        }

This is an internal property in RadPdfViewerElement. So, if you want to access it, it is necessary to use reflection:

https://stackoverflow.com/questions/95910/find-a-private-field-with-reflection 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfViewer and PdfViewerNavigator
Asked by
Claude
Top achievements
Rank 1
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or