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
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.
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(
new
System.Uri(
"DocumentSource;component/Sample.pdf"
, System.UriKind.Relative)).Stream;
this
.pdfViewer.DocumentSource =
new
PdfDocumentSource(str);
2. Load a PDF file from Uri:
this
.pdfViewer.DocumentSource =
new
PdfDocumentSource(
new
System.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.
Kammen
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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 >>
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?
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 >>
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...
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));
What am I doing wrong?
P.S. Sorry for my bad English
@ 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 >>
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?
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;
}
sender.Document ==
null
"System.UnauthorizedAccessException: Invalid cross-thread access error"
occursDo 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 >>
yes, no matter what I've tried, I have not yet managed to see ANY pdf in this viewer
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 >>
Thanks!
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 >>
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
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 >>
I'm attached 2 files.
First - pdf document in Adobe Reader, Second - in Telerik PdfViewer.
See the difference? =)
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.
Kammen
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.
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,
Kammenthe Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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?
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
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.
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
What should I do if I want to not to set the build action to resource?
I have tried to load the pdf file by using what you suggested:
1. Load a PDF file from stream:
Stream str = App.GetResourceStream(
new
System.Uri(
"DocumentSource;component/Sample.pdf"
, System.UriKind.Relative)).Stream;
this
.pdfViewer.DocumentSource =
new
PdfDocumentSource(str);
2. Load a PDF file from Uri:
this
.pdfViewer.DocumentSource =
new
PdfDocumentSource(
new
System.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
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
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 >>