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

Load from stream?

31 Answers 859 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Bryce
Top achievements
Rank 1
Bryce asked on 17 Nov 2011, 08:11 PM
Any example on how I can get this control to load from a memorystream containing the PDF?

Edit: Sorry I figured this out on my own. 

PdfDocumentSource

This seems very very slow though.  After I hand off the PdfDcoumentSource it shows "loading" for a very long time before rendering the document.

31 Answers, 1 is accepted

Sort by
0
Elke.Eichelhard
Top achievements
Rank 1
answered on 18 Nov 2011, 05:24 PM
Hello Bryce,

congratulations on figuring that issue out!
I was`t able to do this.

Could you please advice me with some example code?

Thank you very much.
0
Kammen
Telerik team
answered on 21 Nov 2011, 04:56 PM
Hi Elke.Eichelhard, Bryce,

Thank you for your interest in RadPDFViewer.
There are two ways to open a PDF file in the control.  You need to use PdfDocumentSource class, which provides two options to load a file:

1.     Load a PDF file from stream:

Stream str = App.GetResourceStream(newSystem.Uri("DocumentSource;component/Sample.pdf", System.UriKind.Relative)).Stream;

this.pdfViewer.DocumentSource = newPdfDocumentSource(str);

2.     Load a PDF file from Uri:

this.pdfViewer.DocumentSource = newPdfDocumentSource(newSystem.Uri("DocumentSource;component/Sample.pdf", System.UriKind.Relative));


 We are working on the documentation of the control as we speak and it should be available soon. In the meantime, do not hesitate to contact us if any other questions arise.

As for the performance issue when loading larger documents, this is due to the fact that the pages are shown only after the whole document is loaded. We have scheduled an optimization which will show the pages one by one when they are parsed and that will resolve the problem.

Best wishes,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Wei
Top achievements
Rank 1
answered on 22 Nov 2011, 06:10 PM
The pdf file needs to be loaded from local resource?
0
Iva Toteva
Telerik team
answered on 22 Nov 2011, 06:31 PM
Hello Wei,

In Kammen's examples, the file is added as a resource in the Silverlight project, but that is not a requirement. One option is to use the OpenFileDialog as done in the FirstLook online demo

You can just as well load files that are not on the client machine. For example, if you embed a Sample.pdf file in the Web project, you can load it like this:

<controls:RadPdfViewer x:Name="pdfViewer" Grid.Row="1" DocumentSource="/Sample.pdf" />

PDF files can be opened as long as you can obtain a stream with their content. Note that due to Silverlight’s security policy, only files from a domain with permissive cross-domain policy can be loaded.

Best wishes,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Wei
Top achievements
Rank 1
answered on 22 Nov 2011, 07:05 PM
I solve it. Thank you!
0
Wei
Top achievements
Rank 1
answered on 22 Nov 2011, 10:21 PM
Hi,

I have a file that is generated in runtime with WCF async call. It is located in Silverlightapp.web folder and file name is generated in the runtime. How to write the DocuementSource and display it in browser?
0
Kammen
Telerik team
answered on 24 Nov 2011, 12:51 PM
Hi Wei,

You can create new PdfDocumentSource passing your file as stream. The only thing you need to do is get your file as a Stream and set the DocumentSource property of the viewer like this:
this.pdfViewer.DocumentSource = new PdfDocumentSource(FileAsStream);

Regards,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jen
Top achievements
Rank 1
answered on 29 Nov 2011, 09:32 PM

I have my PDF in my ClientBin, build action set as content, copy Always

when I do this the DocumentSource is null:

System.Uri path = new System.Uri("/testingPDF.pdf", System.UriKind.RelativeOrAbsolute);            
this.pdfViewer.DocumentSource = new PdfDocumentSource(path);

Is there something I'm missing? Build action set wrong?
I also can't get local PDF's to view using the open dialog...
0
Nikituki
Top achievements
Rank 1
answered on 30 Nov 2011, 12:03 PM
Hello,
I'am trying to load PDF document to RadPdfViewer.
var a = new Telerik.Windows.Documents.Fixed.PdfDocumentSource(theMemStream);
var b = new Telerik.Windows.Documents.Fixed.PdfDocumentSource(new Uri(path, UriKind.Relative));
Both times document == null.
What am I doing wrong?

P.S. Sorry for my bad English
0
Kammen
Telerik team
answered on 30 Nov 2011, 06:32 PM
Hello guys, 

@ jen b 

If you want to load PDF file located in ClientBin directory, you should try to use code similar to the following:

this.viewer.DocumentSource = new PdfDocumentSource(new Uri("/ClientBin/Sample.pdf", UriKind.Relative));




@ Nikituki Nikituki 

The PdfDocumentSource is loading the document asynchronously. That is why the Document property is null at the time you try to get it. You should use the Loaded event or the PdfDocumentSource object obtain the loaded document.


Best wishes,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jen
Top achievements
Rank 1
answered on 30 Nov 2011, 07:06 PM
Thanks for the reply,

usualy you don't need to include /ClientBin to the path when its relative (since it should be relative to the .xap IN the ClientBin), but I tried that anyways, waited for it to load asynchronously and finally the source is not null!  A step in the right direction, thanks!

However after setting it to the viewer's DocumentSource, the viewer is still not displaying anything.

Any more ideas?
0
Nikituki
Top achievements
Rank 1
answered on 01 Dec 2011, 07:40 AM
@Kammen
Ok, I'am trying to do this
var a = new Telerik.Windows.Documents.Fixed.PdfDocumentSource(theMemStream);
a.Loaded += new EventHandler(a_Loaded);
      
 
void a_Loaded(object sender, EventArgs e)
{
     pdfViewer.DocumentSource = (Telerik.Windows.Documents.Fixed.PdfDocumentSource)sender;
}
In this case:
sender.Document == null
and "System.UnauthorizedAccessException: Invalid cross-thread access error"  occurs
0
Kammen
Telerik team
answered on 02 Dec 2011, 05:04 PM
Hi Jen, Nikituki,
Do you have the same problem when you load your PDF file from open file dialog of the RadPdfViewer?

@Nikituki Nikituki
Actually RadPdfViewer will handle the asynchronous loading of the document, so all you need to do is to set PdfViewer.DocumentSource property, as described here.

All the best,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
jen
Top achievements
Rank 1
answered on 02 Dec 2011, 05:06 PM
Kammen,
yes, no matter what I've tried, I have not yet managed to see ANY pdf in this viewer
0
Boby
Telerik team
answered on 02 Dec 2011, 05:33 PM
Hello Jen,
Could you please open a support ticket and send us attached some of the problematic PDF documents, so we can investigate the issue further?

Kind regards,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
S W
Top achievements
Rank 1
answered on 21 Dec 2011, 01:01 AM
It simply does not work for our situation.  We are feeding the RadPdfViewer with MemoryStream, which contains one PDF created by Telerik Report.  Any body can help?
Thanks!
0
Kammen
Telerik team
answered on 21 Dec 2011, 06:04 PM
Hi S W,

We are happy to announce that we just rolled out a new version (Q3 SP1) of our tools with a lot of enhancements of PDFViewer including issues related to loading documents generated by Telerik Reporting. If the document in question still does not work, please save a stream you are generating as a file and send it to us in a support ticket to investigate the issue further.


All the best,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Alex
Top achievements
Rank 1
answered on 21 Dec 2011, 11:10 PM
hi kammen,

I am using the trial version RadPdfViewer control, when loading the PDF is destroyed appears strange characters instead of the original content and in some cases does not support pdf of 8, 10 14 MB
0
Kammen
Telerik team
answered on 22 Dec 2011, 05:49 PM
Hello,

It would be great if you open a support ticket and send some PDF files that are not displayed well. In this way, we would be able to look into the import and make the appropriate fixes.


Greetings,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Nikituki
Top achievements
Rank 1
answered on 23 Dec 2011, 08:58 AM
Hi,

I'm attached 2 files.
First - pdf document in Adobe Reader, Second - in Telerik PdfViewer.
See the difference? =)
0
Kammen
Telerik team
answered on 23 Dec 2011, 03:54 PM
Hello Nikituki,

RadPdfViewer is in beta stage and it is normal that there are some issues. We are constantly working on extending the supported features. With every release RadPdfViewer will be able to display the documents better than before.
What you can do in order to help us improve the control is to upload the pdf files instead of screenshots of the result, so that we can look into the content and track down the particular cause of the problem. You can either open a support ticket and attach the files there or upload them somewhere else and post a link in the forums.

Greetings,
Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jane
Top achievements
Rank 1
answered on 03 Jan 2012, 08:06 PM
I tried to display pdf file, load from memorystream. I upgrade telerik controls to 2011Q3 sp1. I still can not get pdf file displayed. Can you provide a example how to do it? Thank you for your help!

This is what I did:
PreviewReportWindow is a childwindow, which has

 

<

 

 

telerik:RadPdfViewer x:Name="pdfViewer"></telerik:RadPdfViewer>

 

 

 

 


in code behind

 

 

 

MemoryStream objfileStream;

 

 

 

public

 

 

PreviewReportWindow(byte[] pdffilebyte)

 

{

InitializeComponent();

objfileStream =

 

new MemoryStream(pdffilebyte, true);

 

objfileStream.Write(pdffilebyte, 0, pdffilebyte.Length);

this

 

 

.pdfViewer.DocumentSource = new PdfDocumentSource(objfileStream);

 

}

I also tried to put the pdf file in \clientbin of  .web project, or in client project. both cases works,  displayed the pdf file. I can open the pdf file from open file dialogue of pdfviewer.

0
Kammen
Telerik team
answered on 04 Jan 2012, 10:52 AM
Hi Jane,

We could not managed to reproduce the problem. This code snippet should do the trick.

MemoryStream ms = new MemoryStream(bytes);
this.pdfViewer.DocumentSource = new PdfDocumentSource(ms);

If you still face problems with the PdfDocumentSource, please provide us a demo application to further investigate where the problem is.

Greetings,

Kammen
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jane
Top achievements
Rank 1
answered on 05 Jan 2012, 11:53 PM
Thank you! I tried to load several pdf files. some files works, but some files cannot been displayed in pdfviewer control.
I switched to save pdf files on the server and  display pdf file in a radhtmlplaceholder,  put the radhtmlplaceholder in a Radwindow.
The only issue I have now is that when I minimize the radwindow(with pdf file), and then maximize the radwindow, the pdf file disappeared. I am not sure how to disable the minimize function of the Radwindow. Can you help me?
0
Konstantina
Telerik team
answered on 10 Jan 2012, 01:32 PM
Hello Jane,

In order to disable the minimize option you need to set the ResizeMode property of the RadWidnow to NoResize. This will disable the sizing of the RadWindow.
However, if you only want to remove the minimize button, then you need to edit the template of the RadWindow. You can do that very easy with Expression Blend. Just drop a RadWindow on the design surface, right-click it and choose from the menu Edit Template->Edit a Copy. Then Blend will generate all the needed resources. Find the button with x:Name PART_MinimizeButton and set its Visibility property to Collapsed. Then apply the style to the RadWindow as explained in this help article.

Hope this helps.

Regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
bhargav
Top achievements
Rank 1
answered on 30 Mar 2012, 05:13 PM
Hi,

I am trying to load a PDF document into the PDF viewer. THe document is stored in database as a byte array and on retrieval i am converting this bytearray to a stream and displaying it using the following code:
byte[] byteArrayPdf=(m_ObjDomainContextFlightQuotation.Get_PDF_By_ID_Results.ToList())[this.radGridHistoryList.Items.IndexOf(this.radGridHistoryList.SelectedItem)].Detail;
           Stream s= new MemoryStream(byteArrayPdf);
           radPDFViewer.DocumentSource = new PdfDocumentSource(s);

But, The PDF file does not show up on my page at all. THe document property of the document source is always null.
From above discussion, i gather that document can be null if the file is corrupted, but the same byte array when written on an aspx page,like below, works fine an hence i dont think the pdf file is corrupt.
Response.BinaryWrite(byteArray);

Please provide me with a solution to this issue?

Note: I am using the 2012.1.221.1050 version of telerik controls for silverlight.
0
Kammen
Telerik team
answered on 04 Apr 2012, 12:50 PM
Hi Bhargav,
We will need a little more information to understand the problem and manage to help you.
Have you tried saving the byte array to a file and then opening it in the viewer using the OpenFileDialog (or directly in our online demo). If the file can be opened successfully, then maybe the problem is somewhere in your application. In that case a sample project that shows the problem (attached to a support ticket) will help us to investigate what is wrong.
In case the PDF file cannot be opened even with the online demo, we would appreciate it if you send us the file itself so that we can inspect it.

Kind regards,
Kammen
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
P
Top achievements
Rank 1
answered on 10 Apr 2012, 02:15 PM
Migrating to Q1 2012 sp of Dlls solved my issue
0
Sasan
Top achievements
Rank 1
answered on 06 May 2012, 03:00 PM
What is the xaml code to load from stream?
What should I do if I want to not to set the build action to resource?
0
Qiping
Top achievements
Rank 1
answered on 27 Sep 2013, 09:48 PM
Hey Kammen,

I have tried to load the pdf file by using what you suggested:

1.     Load a PDF file from stream:

Stream str = App.GetResourceStream(newSystem.Uri("DocumentSource;component/Sample.pdf", System.UriKind.Relative)).Stream;

this.pdfViewer.DocumentSource = newPdfDocumentSource(str);

2.     Load a PDF file from Uri:

this.pdfViewer.DocumentSource = newPdfDocumentSource(newSystem.Uri("DocumentSource;component/Sample.pdf", System.UriKind.Relative));


Both methods need to create the instance new PdfDocumentSource. I have included the reference files:
C:\Program Files (x86)\Telerik\RadControls for Silverlight Q2 2013\Binaries\Silverlight\Telerik.Windows.Controls.FixedDocumentViewers.dll
C:\Program Files (x86)\Telerik\RadControls for Silverlight Q2 2013\Binaries\Silverlight\Telerik.Windows.Documents.Fixed.dll

But the project still say the namespace for PdfDocumentSource could not be found. Any suggestions? Please see the attachment.

Thanks

Qiping
0
Petya
Telerik team
answered on 02 Oct 2013, 03:46 PM
Hi Qiping,

Please refer to this thread where I answered your questions. If there is anything else unclear fell free to get back to us.

Regards,
Petya
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
Bryce
Top achievements
Rank 1
Answers by
Elke.Eichelhard
Top achievements
Rank 1
Kammen
Telerik team
Wei
Top achievements
Rank 1
Iva Toteva
Telerik team
jen
Top achievements
Rank 1
Nikituki
Top achievements
Rank 1
Boby
Telerik team
S W
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Jane
Top achievements
Rank 1
Konstantina
Telerik team
bhargav
Top achievements
Rank 1
P
Top achievements
Rank 1
Sasan
Top achievements
Rank 1
Qiping
Top achievements
Rank 1
Petya
Telerik team
Share this question
or