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

Unable to Save PDF file

1 Answer 28 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Ramesh
Top achievements
Rank 1
Ramesh asked on 02 Jan 2014, 12:09 PM
Hi Telerik,

  I  neeed to save pdf file in my local hard drive  which is opend in RadPdfViewer how to achive this.
  I followed this link but tht sample is not working http://www.telerik.com/community/forums/silverlight/pdfviewer/save-pdf-file.aspx

  it throughing the followimng error "

Error      1              'PdfViewerCommands.Commands.CustomOpenCommand' does not contain a definition for 'viewer' and no extension method 'viewer' accepting a first argument of type 'PdfViewerCommands.Commands.CustomOpenCommand' could be found (are you missing a using directive or an assembly reference?)                c:\users\mandapellyr\desktop\357895_pdfviewercommands\pdfviewercommands\pdfviewercommands\commands\customopencommand.cs                51           22           PdfViewerCommands

"

I am following MVVM Pattern how to this in this pattern

I tried one sample ,  Here i don't know where i need to give the save path in SaveExexute() Method.

 Even I am unable to load the pdf file in MVVM Pattern.


View Model:

  
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Documents.Fixed;
 
 
using System.ComponentModel;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight.Command;
using System.IO;
 
 
namespace PDFViewerMultifulPDFsDisplayMVVM
{
    public class PDFViewmodel
    {
        private Stream documentStream;
 
      public  PDFViewmodel()
        {
 
            showPdf();
            SaveCommand = new RelayCommand(SaveExexute);
        }
      public RelayCommand SaveCommand { get; set; }
 
        private PdfDocumentSource _pdfsou;
        public PdfDocumentSource pdfso
        {
 
            get { return _pdfsou; }
            set { _pdfsou = value; }
        }   
 
        public void showPdf()
        {
 
            var str = App.GetResourceStream(new System.Uri("/PDFViewerMultifulPDFsDisplayMVVM;component/RadPDFViewer_For_Silverlight_and_WPF.pdf", System.UriKind.Relative)).Stream;
            this.pdfso = new PdfDocumentSource(str);         
            //this.pdfviewer.DocumentSource = new PdfDocumentSource(str);
            
        }
        public void SaveExexute()
        {
 
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "PDF file (*.pdf)|*.pdf";
         
           if (saveFileDialog.ShowDialog() == true)
            {
                using (Stream saveStream = saveFileDialog.OpenFile())
                {
                    documentStream.Seek(0, SeekOrigin.Begin);
                    documentStream.CopyTo(saveStream);
                    documentStream.Flush();
                    saveStream.Flush();
                }
            }
 
        }
 
    }
}


<UserControl x:Class="PDFViewerMultifulPDFsDisplayMVVM.StategicView"
              
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:vm="clr-namespace:PDFViewerMultifulPDFsDisplayMVVM"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <UserControl.Resources>
        <vm:PDFViewmodel x:Key="pdfraja"/>
    </UserControl.Resources>
     
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource pdfraja}">
         
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
 
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition Height="200" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
 
            </Grid.RowDefinitions>     
         <telerik:RadToolBar DataContext="{Binding ElementName=PdfViewer, Path=Commands}"  Grid.Row="3">
                <telerik:RadButton  Padding="4" Command="{Binding OpenPdfDocumentCommand}">
                    <ToolTipService.ToolTip>
                        <TextBlock Text="Open"/>
                    </ToolTipService.ToolTip>
                    <Image Source="/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/open.png"
                                                 Stretch="None" />
                </telerik:RadButton>
 
                <telerik:RadButton  Padding="4" DataContext="{StaticResource pdfraja}"  Command="{Binding SaveCommand}">
                    <ToolTipService.ToolTip>
                        <TextBlock Text="Save"/>
                    </ToolTipService.ToolTip>
                    <Image Source="/PDFViewerMultifulPDFsDisplayMVVM;component/Image/save.png"
                                                 Stretch="Fill" />
                </telerik:RadButton>               
            </telerik:RadToolBar>
 
            <telerik:RadPdfViewer x:Name="PdfViewer" DocumentSource="{Binding Pdfso}" Grid.Row="4" Height="400" />
        </Grid>
    </Grid>
</UserControl>

Kindly help me anyone



1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 07 Jan 2014, 09:24 AM
Hello Ramesh,

You can try using the following SDK example which shows how to implement custom open and save commands.
If you have any problems with this example or some other concerns do not hesitate to contact us again.

Regards,
Alexander
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
PDFViewer
Asked by
Ramesh
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or