Thanks.
19 Answers, 1 is accepted
Although quite simple I do believe that as open it also should be in toolbar.
private
SaveFileDialog saveFileDialog;
private
byte
[] _document;
public
byte
[] Document
{
get
{
return
_document; }
set
{
if
(_document != value)
{
_document = value;
OnPropertyChanged(
"Document"
);
}
}
}
private
void
InitializeSaveDialog()
{
saveFileDialog =
new
SaveFileDialog();
saveFileDialog.DefaultExt =
"pdf"
;
saveFileDialog.Filter =
"pdf Files (*.pdf)|*.pdf|All files (*.*)|*.*"
;
saveFileDialog.FilterIndex = 1;
}
private
void
Print_Click(
object
sender, System.Windows.RoutedEventArgs e)
{
InitializeSaveDialog();
if
(saveFileDialog.ShowDialog() ==
true
)
{
using
(Stream fs = (Stream)
this
.saveFileDialog.OpenFile())
{
fs.Write(Document, 0, Document.Length);
fs.Close();
}
}
}
In view only needed to add a new radbutton with Print_Click event on Click and it does the trick.
PS. someone mark it as answer. (if so simple why not a command as print and open?)
We have decided that it is not appropriate to introduce a save command until we implement export to PDF.
RadPdfViewer does not simply display PDF files, it parses the files to create RadFixedDocument. This means that theoretically you can create a document from scratch.
At this state, however, keeping the initial stream in memory is enough to complete the Save functionality. So there is one more thing to do to accomplish this task except the part you have already done. You should create a custom command that overrides OpenPdfDocumentCommand. There you should store the input stream to be used by the Save command later.
It will also be a better approach if you moved the Save logic in new command that inherits FixedDocumentViewerCommandBase. Please find attached a demo illustrating how you can create a custom command in RadPdfViewer.
Regards,
Kammen
the Telerik team
I also have the same requirement to save pdf file,I also downloaded your custom open command demo but still i didn't got it how to achieve save command functionality.Would you please provide me same example including save functionality also? Then it will be much clear to me.
Please advice.
Thanks and best regards,
Roshan Salvi.
Please find attached a modified version of the demo, which includes two custom commands - an open document command, which saves the stream in a property, and a save command that writes this stream to a file. Hopefully, this approach will match the requirements of your application.
All the best,Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I have similar requirement. I have server side pdf files available for viewing in the silverlight PDfViewer.
I have a button click event on a page that loads the file across the network.
private void Button_Click_BlackMP(object sender, RoutedEventArgs e)
{
path = "/Report.pdf";
this.RadPDFHolder.DocumentSource = new PdfDocumentSource(new System.Uri(path, System.UriKind.RelativeOrAbsolute));
Are you going to implement an Export (or save as) to PDF?
Export is probably not the terminology since the users would expect that the viewer is showing a pdf, but from my understanding I believe it to be converted into a RadFixedDocument at this stage.
Cheers
Michael
We have export to PDF from RadPdfDocument in our to-do list, however we have not scheduled it yet.
Currently, the only way to save the file as PDF is to create your own save command. You can check the demo that Iva has provided. There you can see a simple implementation of a save command.
Greetings,
Kammenthe Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I dont think the demo is applicable since in my case, the document is streamed from the server
ie. this.RadPDFHolder.DocumentSource = new PdfDocumentSource(new System.Uri(path, System.UriKind.RelativeOrAbsolute));
I am not opening the file on the client side so there is no client side stream to access and subsequently save.. .
Mike
Hello Mike,
If you have full control over the documents that will be displayed in RadPdfViewer (the user cannot open PDF files on his own), then you should probably use the other constructor of PdfDocumentSource, which accepts a stream as a parameter.
First, you should open a stream from the Uri you have, store this stream, and later when the user tries to save the file, you will pass this stream to the user. You should note that RadPdfViewer runs on the client side, so saving must happen using the SaveFileDialog.
You can open a stream to a Uri using WebClient class. Your code should be something like this:
System.Net.WebClient webClient =
new
System.Net.WebClient();
webClient.OpenReadCompleted += (
object
sender, System.Net.OpenReadCompletedEventArgs e) =>
{
if
(e.Error ==
null
)
{
//Save Stream here for future export using SaveFileDialog.
this
.viewer.DocumentSource =
new
PdfDocumentSource(e.Result);
}
}
;
webClient.OpenReadAsync(MyUri, UriKind.RelativeOrAbsolute));
This is what RadPdfViewer does internally when you instantiate its DocumentSource using a Uri. In this way, you will set the document source of the viewer and will be able to use the stream when export is initiated.
Kind regards,
Kammenthe Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I am also having this issue. I assume that there is still no save command?
If I load the document like this, instead of letting the viewer load the document, the loading progress bar is not being shown. Is there any way I can show the loading progress bar?
System.Net.WebClient webClient =
new
System.Net.WebClient();
webClient.OpenReadCompleted += (
object
sender, System.Net.OpenReadCompletedEventArgs e) =>
{
if
(e.Error ==
null
)
{
//Save Stream here for future export using SaveFileDialog.
this
.viewer.DocumentSource =
new
PdfDocumentSource(e.Result);
}
}
;
webClient.OpenReadAsync(MyUri, UriKind.RelativeOrAbsolute));
Thanks
Henrik
You can try to create the PdfDocumentSource using the Uri instead of opening the stream by yourself. Then, in the Save command, you can use the Uri to download the stream and save it. In fact, we recommend this approach, because using the same stream as RadPdfViewer can cause unexpected behavior in some cases.
If you want to show a busy indicator when you download the stream in the save command, you can use your own in your application as the save command is not an operation in RadPdfViewer.
Hope this answers your question.
Regards,
Kammen
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Ok thank you, I will do that.
Thanks
Henrik
I tried doing this without the Open command since I'm opening a pdf via memory stream.
However, i wasn't able to save the pdf into file because the CustomSaveCommand can't the pdf viewer stream.
It is always returning False in this part:
Public Overrides Function CanExecuteOverride(parameter As Object) As Boolean
Return documentStream IsNot Nothing AndAlso documentStream.Length > 0
End Function
Below is how I load the PDF. Please see if there is something I'm missing.
Thank You
Dim ms As New MemoryStream()
ms.Write(e.Result, 0, e.Result.Length)
Dim winPdf As New PdfLabelViewer
winPdf.pdfViewer.DocumentSource = New PdfDocumentSource(ms)
winPdf.Show()
How to pass parameters to customsavecommand
Thanks
Bindu
I'm afraid I don't quite understand your question. The save command discussed in this thread is a custom command. That said, how you'd invoke the command and whether you would use a parameter depends on you. For example, the following snippet shows that I've passed the value of a TextBox as a parameter to the command:
<
telerik:RadButton
Padding
=
"4"
DataContext
=
"{Binding ElementName=_this, Path=Commands}"
Command
=
"{Binding SaveCommand}"
CommandParameter
=
"{Binding ElementName=pathTextBox, Path=Text}"
>
Please note that the Silverlight framework does not allow direct access to the file system.
Regards,
Petya
Telerik
It worked great.
Thanks:)
Thanks in advance
Bindu
RadPdfViewer is responsible for showing PDF documents in one of the approaches listed in this article. The Custom Save Command sample provides a base that can be extended, so that all documents shown in the control can also be saved to a desired location. However, the control does not keep information regarding the name or the path to the file that you are showing, so this is up to you to implement.
Like I mentioned in my previous reply, Silverlight's framework imposes restrictions preventing you to access the file system on the client which is why I'd advise you to try and parse the file name from the uri passed to the OpenCommand.
Regards,
Petya
Telerik
What i was trying to get is, i need the PDF filename that is opened and bind the filename to a label or textbox
Thanks
Bindu
Thanks :)