How to call unload when pdfViewer is closed fastly

Hi! I'm using PDFViewer component on angular material dialog. Happens that if i open the dialog with file, and then i close fastly the dialog, i cant call pdfviewer.unload().

So i think that if i dont call unload, the pdf will keep in cache of backend. How i can force unload document?


5 Replies

BE Benjamin August 9, 2021 05:09 PM UTC

I found a workaround: this.pdfViewer.viewerBase.unloadDocument(this.pdfViewer.viewerBase); this method call unload endpoint and caché is cleared. But still one console error: ( I supose that is because pdfRenderPages is not loaded). How i can cancel load? i dont want console error


core.js:6210 ERROR TypeError: Cannot set property 'min' of undefined

    at Toolbar$1.updateTotalPage (ej2-pdfviewer.es2015.js:40467)

    at PdfViewerBase.initPageDiv (ej2-pdfviewer.es2015.js:30723)

    at PdfViewerBase.pageRender (ej2-pdfviewer.es2015.js:28974)

    at PdfViewerBase.requestSuccess (ej2-pdfviewer.es2015.js:28900)

    at AjaxHandler.loadRequestHandler.onSuccess (ej2-pdfviewer.es2015.js:28830)

    at AjaxHandler.successHandler (ej2-pdfviewer.es2015.js:36617)

    at AjaxHandler.stateChange (ej2-pdfviewer.es2015.js:36592)

    at XMLHttpRequest.httpRequest.onreadystatechange [as __zone_symbol__ON_PROPERTYreadystatechange] (ej2-pdfviewer.es2015.js:36511)

    at XMLHttpRequest.wrapFn (zone-evergreen.js:1218)

    at ZoneDelegate.invokeTask (zone-evergreen.js:399)



DM Dhivyabharathi Mohan Syncfusion Team August 10, 2021 09:13 AM UTC

Hi Benjamin, 
 
 
Thank you for contacting Syncfusion support. 
 
 
We have checked by unloading the PDF document using the unload() method. We were unable to reproduce the reported script error while invoking unload method. We have shared the sample in which we tried to replicate this issue. 
 
 
 
 
Code snippet: 
 
 
  <button (click)="unload()">unload</button> 
 
 unload() { 
    var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0]; 
    viewer.unload(); 
  } 
 
 
 
 
Could you please try the sample and revert us, whether the reported issue is resolved or not? If the issue is not resolved, kindly share the modified sample in which you are facing this issue or kindly share the video for replicating this issue. It will be helpful for us to investigate further and provide the details at the earliest. 
 
 
Regards, 
Dhivya. 



BE Benjamin August 10, 2021 02:03 PM UTC

Hi Dhivya, happens that you aren't using angular material dialog. https://stackblitz.com/edit/angular-aqxaqz-rojhsf?file=app%2Fapp.module.ts 


As you can see in the stackblitz, when we press open button, and then close inside of dialog (when pdfViewer is loading), so console has an error: 



BE Benjamin August 10, 2021 03:43 PM UTC

Also, you can see in network panel of chrome DevTools, that when this error happens: "Error: Cannot set property 'min' of undefined", the endpoint unload is not being called, and i suppose that PDF file still in cache of backend.




DM Dhivyabharathi Mohan Syncfusion Team August 11, 2021 11:34 AM UTC

Hi Benjamin, 
 
 
We have checked the sample you shared. We suspect that the script error occurs because you have invoked the close method to close the material dialog before the PDF Viewer component is rendered in the UI. We suggest you to use the below code snippet to get the issue resolved. We have shared the modified sample and code snippet for your reference. 
 
 
 
Code snippet: 
 
close() { 
    setTimeout(() => { 
      this.matDialog.close(); 
    }, 1000); 
  } 
 
 
 
 
Kindly try this and revert us, if you have any concerns. 
 
 
Regards, 
Dhivya. 


Loader.
Up arrow icon