TaTo30 / vue-pdf

PDF component for Vue 3
https://tato30.github.io/vue-pdf/
MIT License
463 stars 65 forks source link

Interrupt the PDF loading #23

Closed das-friday-night closed 1 year ago

das-friday-night commented 1 year ago

Hello I have been playing VuePDF for over a week, it is one of the best PDF tools in Vue3 ecosystem. I think it will be really useful if there is a way to interrupt the PDF loading process. For large PDF file, if the user don't want to wait or click the wrong file and want to change another one immediately, the interrupt mechanism will kill currrent PDF loading gracefully before it start to load a new one.

If I switch another view while the pdf is loading, the following error will popout:

@tato30_vue-pdf.js?v=9686917e:32013 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'parentNode') at @tato30_vue-pdf.js?v=9686917e:32013:31.
TaTo30 commented 1 year ago

To cancel the pdf loading you can do it by accessing to pdf's destroy function, maybe this can work:

const { pdf } = usePDF(pdf014)

function destroyPdf(){
  pdf.value?.destroy()
}
das-friday-night commented 1 year ago

To cancel the pdf loading you can do it by accessing to pdf's destroy function, maybe this can work:

const { pdf } = usePDF(pdf014)

function destroyPdf(){
  pdf.value?.destroy()
}

Yep it works. And this also clear the memory usage for holding the PDF file. Without using the destory() function I always enter into the out-of-memory issue. Thank you a lot.