FranckFreiburger / vue-pdf

vue.js pdf viewer
MIT License
2.23k stars 522 forks source link

when enter incorrect password, can not open the other pdf Unless refresh #220

Open lory8545 opened 4 years ago

lory8545 commented 4 years ago
 - vue-pdf 4.0.8
 - vue.js 2.5.2
 - webpack 3.6.0
 - browser chrome 81.0.4044.138
 - OS  win10
lory8545 commented 4 years ago

当传入错误的密码时, 除非刷新 ,要不然再也打不开其它的PDF文件了, 即使该pdf文件不需要密码

nickbetsworth commented 3 years ago

I've just run into the same issue on v4.2.0

@lory8545 did you manage to find a workaround for this?

Steps to reproduce:

  1. Load a page with an instance of vue-pdf pointing to a password protected PDF
  2. Navigate to a separate page with an instance of vue-pdf pointing to an unprotected PDF
  3. Notice that the unprotected file is not loaded, and any subsequent attempts to load different PDF files have no effect

The issue is probably reproducible with multiple instances of vue-pdf on a single page, but I haven't tested this.

nickbetsworth commented 3 years ago

@FranckFreiburger I think the problem may stem from here https://github.com/FranckFreiburger/vue-pdf/blob/master/src/pdfjsWrapper.js#L67

  1. pdfDoc === null when a password has not yet been successfully provided.
  2. pendingOperation is thus NOT cleared, and this prevents the next PDF from loading
this.destroy = function() {
    if ( pdfDoc === null )
        return;

    // Aborts all network requests and destroys worker.
    pendingOperation = pdfDoc.destroy();
    pdfDoc = null;
}

Would it be safe for us to just re-initialise the pendingOperation if the document hasn't been loaded?

if ( pdfDoc === null ) {
    pendingOperation = Promise.resolve();
    return;
}

I've given this a quick test run locally, and it seems to resolve the issue.

wdf-996 commented 9 months ago

You should watch "reason" params, eg:

handleNeedPsw: function (updatePassword, reason) {
        if (reason === 'NEED_PASSWORD') {
          updatePassword(prompt('该文件已加密,请输入密码'))
        }
        if (reason === 'INCORRECT_PASSWORD') {
          this.$message({
            message: '密码错误',
            type: 'error',
          })
          this.src = ''
          this.loadingProgress = '0%'
        }
}

other, you should edit the file: https://github.com/FranckFreiburger/vue-pdf/blob/master/src/pdfjsWrapper.js#L67

this.destroy = function () {
      if (pdfDoc === null) {
        pendingOperation = Promise.resolve();
        return;
      }

      // Aborts all network requests and destroys worker.
      pendingOperation = pdfDoc.destroy();
      pdfDoc = null;
 };