Get path of opened PDF

7 posts, 1 answers
  1. Mark
    Mark avatar
    52 posts
    Member since:
    Sep 2007

    Posted 27 Apr 2013 Link to this post

    Hello

    When I open a PDF using the "Open" button on the radtoolbar, I'd like to get the path of the selected PDF.  What's the best way to do this?  It would also work to pull this as a property from the pdfdocumentsource object etc. if available.

    Thanks
    Mark
  2. Wenjie
    Wenjie avatar
    35 posts
    Member since:
    Mar 2013

    Posted 01 May 2013 Link to this post

    Pdfviewer come with no toolbar.The toolbar in samples is handmade.You can replace it.here my code.
    PdfViewerModel pdfViewerViewModel;
     
       private void Window_Loaded(object sender, RoutedEventArgs e)
       {
          pdfViewerViewModel = new PdfViewerModel();
          this.PdfRoot.DataContext = pdfViewerViewModel;
       }
     
       private void btnLoadFile_Click(object sender, RoutedEventArgs e)
        {
                e.Handled = true;
                 
                string strPdfFilenName = "";
                var dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.Filter = "PDF files (*.pdf)|*.pdf";
     
                if (dlg.ShowDialog().Value)
                {
                    strPdfFilenName = dlg.FileName;
     
                    FileStream fstreamLoaded = new FileStream(strPdfFilenName, FileMode.Open, FileAccess.Read);
     
                    fstreamLoaded.CopyTo(mstreamPdfShow);
     
                    pdfViewerViewModel.mstreamPdfShow = mstreamPdfShow;
                }
     
         }
     
        class PdfViewerModel : INotifyPropertyChanged
        {
                 
        private System.IO.MemoryStream _mstreamPdfShow;
     
            public System.IO.MemoryStream mstreamPdfShow
            {
                get
                {
                    return this._mstreamPdfShow;
                }
                set
                {
                    if ((this._mstreamPdfShow != value))
                    {
                        this._mstreamPdfShow = value;
                        OnPropertyChanged("mstreamPdfShow");
                    }
                }
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
     
            protected void OnPropertyChanged(string propertyName)
            {
                PropertyChangedEventHandler handler = PropertyChanged;
     
                if (handler != null)
                {
                    handler(this, new PropertyChangedEventArgs(propertyName));
     
                }
            }
     
        }


    <Grid Name="PdfRoot" >
         <Grid.RowDefinitions>
              <RowDefinition Height="Auto"></RowDefinition>
              <RowDefinition Height="*"></RowDefinition>
         </Grid.RowDefinitions>
     
        <ToolBar DataContext="{Binding ElementName=c1PdfViewer1, Path=Commands}">
         <Button Click="btnLoadFile_Click" />
                             
         <telerik:RadButton Command="{Binding PageUpCommand}" />
        </ToolBar
         
        <Grid  Grid.Row="1">
            <telerik:RadPdfViewer Name="c1PdfViewer1" 
              DocumentSource="{Binding mstreamPdfShow, Converter={StaticResource PdfDocumentSourceValueConverter}}">
            </telerik:RadPdfViewer>
        </Grid>
    </Grid>                   
  3. UI for WPF is Visual Studio 2017 Ready
  4. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 02 May 2013 Link to this post

    Hello everyone,

    @ Wenjie: Thank you for sharing your code.

    @ Mark: The scenario you would like to achieve is not possible with the OpenCommand that comes out-of-the-box. However, you can create a custom open command based on the default one like shown in this SDk example. In the Execute method you can obtain the file path of the file that is selected in the dialog like this:
    if (dialog.ShowDialog() == true)
      {
          string FileName = dialog.FileName;
          //...

    I hope the provided information helps! Let us know if you have further questions.

    Kind regards,
    Boryana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Mark
    Mark avatar
    52 posts
    Member since:
    Sep 2007

    Posted 03 May 2013 Link to this post

    Thanks Wenji and Boryana.

    @Boryana: I was able to wire up the custom commands per the SDK.  However, in so doing the other features of the toolbar appear not to work now.  Will I need to provide custom command classes for each of those functions now?  (zoom combobox, zoom up/down arrors, etc)

    Thanks
    Mark
  6. Mark
    Mark avatar
    52 posts
    Member since:
    Sep 2007

    Posted 06 May 2013 Link to this post

    I'm opening a support ticket on this....

    Thanks
    Mark
  7. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 07 May 2013 Link to this post

    Hello Mark,

    Please make sure all required assembly references have been added to your project. Also, can you please share whether you've changed something in the setup shown in the SDK example.

    Creating custom commands in the demonstrated way and binding them to the buttons in the toolbar should not affect the other commands and they should be working as expected. Note that in the demo, the DataContext of the RadToolBar is set to commands that come out of the box and the custom commands have another context set:
    <telerik:RadButton Padding="4" DataContext="{Binding ElementName=_this, Path=Commands}"  Command="{Binding OpenCommand}">
    where _this is MainWIndow.

    I hope this helps! Let us know if you are still facing difficulties.
     
    All the best,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Mark
    Mark avatar
    52 posts
    Member since:
    Sep 2007

    Posted 08 May 2013 Link to this post

    Thanks Petya! 

    I had bound the datacontext of the entire radToolBar to the page when it should have been bound to the radPDFViewer.  Only the individually customized radButtons need their context bound to the page to access the new Commands dependency property.

    I've updated the forum post as well.

    Thanks for your help
    Mark
Back to Top
UI for WPF is Visual Studio 2017 Ready