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

OnDocumentLoaded working?

6 Answers 316 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 16 May 2012, 07:57 PM
How can I be sure that PDFViewer has finished loading a document when using the ReadOnDemand mode?

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

Sort by
0
Kammen
Telerik team
answered on 19 May 2012, 08:25 AM
Hello Victor,
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 >>

0
Victor
Top achievements
Rank 1
answered on 20 May 2012, 10:01 PM
Hello Kammen,

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


0
Victor
Top achievements
Rank 1
answered on 21 May 2012, 07:46 AM
Ok, I found out that the loaded event only fires when the ReadingMode is set to AllAtOnce:

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




0
Kammen
Telerik team
answered on 24 May 2012, 01:18 PM
Hello 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 >>

0
Victor
Top achievements
Rank 1
answered on 05 Jun 2012, 04:32 PM
Hello Kamen,

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


0
Kammen
Telerik team
answered on 07 Jun 2012, 01:01 PM

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,

Kammen
the Telerik team

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

Tags
PDFViewer
Asked by
Victor
Top achievements
Rank 1
Answers by
Kammen
Telerik team
Victor
Top achievements
Rank 1
Share this question
or