I've setup a small sample app and the OnDocumendLoaded event does not fire.
Is this event already part of the documentation and/or is there some sample code available?
Kind regards,
Victor
6 Answers, 1 is accepted
As it cannot be determined when a document is entirely loaded in ReadOnDemand mode, we have decided to raise "fake" Loaded event when the DocumentSource is changed so that you can dispose your previous stream. The event in question is PdfDocumentSource.Loaded.
All the best,
Kammen
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I tried this event to but it only fires if I use the Import()-Method which I don't want.
Here is my code in VB:
PdfLoadStream = New FileStream(PdfPfad, FileMode.Open)
PdfDoc = New PdfDocumentSource(PdfLoadStream)
AddHandler PdfDoc.Loaded, AddressOf OnDocumentLoaded
PDFViewer.DocumentSource = PdfDoc
Sub OnDocumentLoaded(sender As Object, e As EventArgs)
PdfLoadStream.Close()
End Sub
The pdf is loaded and shown in the viewer but the event doesn't fire.
The documentation is still lacking some examples for the more "advanced" stuff.
Regards,
Victor
PDFViewer.DefaultFormatProviderSettings.ReadingMode = FormatProviders.ReadingMode.AllAtOnce
If I set it to OnDemand nothing happens.
I just wished that I would have found this somewhere in the documentation (I couldn't even find an explationation of the ReadingMode property - so the document is loaded asynchronously even when the ReadingMode is set to AllAtOnce ).
Regards,
Victor
When using ReadOnDemand mode, RadPdfViewer must have an open stream all the time, in case a new page is requested and it should load some data. This means that you cannot close our stream until you are sure that it will no longer be used - i.e. when you assign a new document source.
That is why when a new PdfDocumentSource is set, the old one will get Loaded event. This indicates that the old source will no longer use its stream and it is now safe to close the stream. You can try this scenario by opening a new document using the open button or just replace the DocumentSource through code behind. Then you should get the Loaded event and you may close your stream.
Regards,
Kammen
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Thank you for the explanation but I was in no way able to get this event.
I can only use ReadingMode.OnDemand because using AllAtOnce would mean that loading a 350 page PDF document will consume about 1 GByte of memory. But when using OnDemand the Pdf file is locked so loading it again will cause an IOException because the file is locked by the viewer.
So what I really prefer would be an example that shows how the loaded event gets fired when using ReadingMode.OnDemand.
Because in my application I want to open several windows with a PDF viewer control each time I have to copy the PDF file in a temp file and load that PDF file to avoid the IOException.
Is there a way to release some memory consumed by the PDF viewer (I don't like using GC.Collect() too much).
Regards,
Victor
Hi Victor,
Thank you for the follow up. Actually there is indeed a bug in the official version and the event is not fired.
We have prepared a demo application that shows how you can get the Loaded event when the other document is opened. For the demo to work, you should use and internal build prepared after the service pack, for example the 2012.1.528 version of the DLLs. You can download internal builds from your account.
Here is an explanation of the memory
1. When you are using the ReadOnDemand mode, the DocumentSource keeps the stream (file) opened for reading. That is why you cannot open it again.
3. RadPdfViewer caches some data in order to be faster. Therefore sometimes (for example when the PDF file contains big images) or the files are big, the consumed memory can rise. However, all the memory will be freed once it is no longer used.
Greetings,
Kammenthe Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>