To Unload or Unload(boolean)?

After unloading a document I noticed that there was still a page count value present in one of my bound controls.  It seems that Unload() only unloads the document from view, but it is still present in the control:

Console.WriteLine("Before Unload(): {0}", PDFViewer.LoadedDocument.Pages.Count);
PDFViewer.Unload();
Console.WriteLine("After Unload(): {0}", PDFViewer.LoadedDocument.Pages.Count);

Both of the lines above return the same number, even though there is not PDF currently displayed in the viewer.  It was only after going to the documentation that I discovered that in order to dispose of the document you need to use Unload(true).  Also, you can use Unload(false)and get the same result as simply Unload().

I'm just curious as to why the options exist.

1 Reply 1 reply marked as answer

DG Deepak Gunasekaran Syncfusion Team September 15, 2020 04:49 PM UTC

Hi Matthew, 
 
The Unload(); and Unload(false); methods perform the same operation of unloading all the UI Elements that are used to display the PDF document pages and its contents by clearing the UI related resources. However, the complete document related resources will be cleared along with the UI resources only if the Unload(true); is used.  
 
The purpose of the option provided to not clear the complete document resource, is that a user may load the PDF using PdfLoadedDocument object, and that object might be used, modified for further operations in his application even after unloading the document PDF Viewer, which may or may not requires PDF Viewer such as extracting text. 
 
 
In that case, the document resources should be disposed only from the user end once the document related resources are no more needed by setting the Unload(true) or by disposing the object as PdfViewer.LoadedDocument.Close(true) if the document is loaded using file path.  
 
Note: The Unload methods are exposed in the earlier stage of development and the LoadedDocument object is exposed in PDF Viewer few releases after for the purpose of getting modified details of annotations, form fields etc., 
 
Please let us know if you need any further assistance. 
 
Regards, 
Deepak G 


Marked as answer
Loader.
Up arrow icon