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
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 buttonthis.radPdfViewerNavigator1.OpenButton.Visibility = ElementVisibility.Collapsed;
//3. page numberint pageIndex = int.Parse(this.radPdfViewerNavigator1.CurrentPageTextBox.Text);
//4. total pagesint 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();
}
publicvoidLoadDocument(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: