This is a migrated thread and some comments may be shown as answers.

Get path of opened PDF

6 Answers 277 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 28 Apr 2013, 02:13 AM
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

6 Answers, 1 is accepted

Sort by
0
Wenjie
Top achievements
Rank 1
answered on 01 May 2013, 04:57 PM
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>                   
0
Boryana
Telerik team
answered on 02 May 2013, 06:48 AM
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.

0
Mark
Top achievements
Rank 1
answered on 03 May 2013, 04:22 PM
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
0
Mark
Top achievements
Rank 1
answered on 06 May 2013, 09:43 PM
I'm opening a support ticket on this....

Thanks
Mark
0
Accepted
Petya
Telerik team
answered on 07 May 2013, 12:44 PM
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.

0
Mark
Top achievements
Rank 1
answered on 08 May 2013, 01:44 PM
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
Tags
PDFViewer
Asked by
Mark
Top achievements
Rank 1
Answers by
Wenjie
Top achievements
Rank 1
Boryana
Telerik team
Mark
Top achievements
Rank 1
Petya
Telerik team
Share this question
or