FranckFreiburger / vue-pdf

vue.js pdf viewer
MIT License
2.21k stars 519 forks source link

The progress event can't return document load progress correctly #38

Open Jude214 opened 6 years ago

Jude214 commented 6 years ago

In my project, the pdf component's progress event just return 'NaN' or '1' that I can't use the value for monitoring the pdf document loading progress. See the phenomenon below: In the pdf.vue source file, the parameter status in loadingTask.onProgress method has a total property whose value is 'undefined', so the ratio variable is undefined too and the 'onProgress' event method passes on an NaN with 'Math.min(ratio, 1)'. Here's the printscreen: image And next time, the 'onProgress' method returns value '1', see the printscreen:

ddbfe987-149f-4f6e-9562-e469b801241b

It seems that something was wrong when calculating the loading progress of the pdf document.

FranckFreiburger commented 6 years ago

see PDFJS issue https://github.com/mozilla/pdf.js/issues/9103

testingSec commented 1 month ago

Muchas Gracias!, me abriste los ojos!

puedes hacer lo siguiente:

pdfSrc.value = pdf.createLoadingTask(pdfUrl.value, { onProgress: progress });

function progress(status) { const ratio = status.loaded / status.total; loadedRatio.value = Math.min(ratio, 1); if (loadedRatio.value === 1) { clearTimeout(timerId); timerId = setTimeout(() => { showProgressBar.value = false; loadedRatio.value=0; actionMsgProcess(false);

  if (props.isPrintPDF) {
    listenToPrint();
  }
}, 1000);

} }

esa es mi implementacion, quizas te ayude.-

testingSec commented 1 month ago

yo lo tengo funcionando, si necesitan ayuda puedo subir mi componente completo