vue-pdf icon indicating copy to clipboard operation
vue-pdf copied to clipboard

Browser zoom issue: pdfRender.cancel() is undefined

Open stofi opened this issue 3 years ago • 6 comments

Hi, I have discovered a weird bug that seems to be related to the zoom level of my browser. pdfjsWrapper.js throws a TypeError if I try to mount the pdf component unless the i have the zoom set at the default 100% (or at 50% on an HDPI enabled)

My browser: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0

Edit: I created a repository and reproduced this on my laptop with Safari and Chrome, with the same behavior. https://github.com/stofi/vue-pdf-resize-issue

TypeError: pdfRender.cancel() is undefined
    renderPage pdfjsWrapper.js:196
    resize componentFactory.js:76
    VueJS 4
    method backend.js:3552
    handler resize-sensor.vue:49
    VueJS 11
    update resize-sensor.vue:39
    VueJS 33
client.js:103
Uncaught (in promise) TypeError: this.messageHandler is null
    getAnnotations pdf.js:14354
    getAnnotations pdf.js:12869
    pendingOperation pdfjsWrapper.js:236
    promise callback*PDFJSWrapper/this.renderPage pdfjsWrapper.js:233
    pdfRenderOperation pdfjsWrapper.js:263
    promise callback*PDFJSWrapper/this.renderPage/pendingOperation< pdfjsWrapper.js:257
    promise callback*PDFJSWrapper/this.renderPage pdfjsWrapper.js:233
    resize componentFactory.js:76
    VueJS 4
    method backend.js:3552
    handler resize-sensor.vue:49
    VueJS 5
pdf.js:14354

stofi avatar Jul 20 '21 17:07 stofi

I have taken a look at the source, to see if I can figure out what causes the issue.

But I don't really understand the intention behind this piece of code:

https://github.com/FranckFreiburger/vue-pdf/blob/1a47de972abefd2079a4e23485041f08d9f68aab/src/pdfjsWrapper.js#L190-L200

Doesn't this always return from the renderPage function unless pdfRender === null?

stofi avatar Jul 20 '21 18:07 stofi

@stofi Did you end up finding a resolution to this? I'm looking for one, as well. If I find anything, I'll share.

xeno avatar Jul 22 '21 15:07 xeno

@xeno my resolution was to wrap vue-pdf in a wrapper component with errorCaptured hook, to prevent nuxt rerouting to an error page. The pdf seems to render fine despite this error.

<script>
import pdf from 'vue-pdf'

export default {
  name: 'PdfViewer',
  components: {
    pdf,
  },
  props: {
    src: {
      type: String,
      default: '',
    },
  },
  errorCaptured() {
    return false
  },
}
</script>

stofi avatar Jul 25 '21 18:07 stofi

A different solution, found in Issue #334

In package.json, instead of vue-pdf ^4.3.0 use "vue-pdf": "4.2.0",

I also had to add "pdfjs-dist": "2.5.207", to compile.

Credit for this solution goes to the poster in #334

windsongdv avatar Oct 21 '21 20:10 windsongdv

A different solution, found in Issue #334

In package.json, instead of vue-pdf ^4.3.0 use "vue-pdf": "4.2.0",

I also had to add "pdfjs-dist": "2.5.207", to compile.

Credit for this solution goes to the poster in #334

That did not work for me and just caused other problems.

CloudMunk avatar Nov 10 '21 11:11 CloudMunk

and i have a same question In package.json, instead of vue-pdf ^4.3.0 use "vue-pdf": "4.2.0",

I also had to add "pdfjs-dist": "2.5.207", to compile. but this version do not working

sohib-code avatar May 16 '22 06:05 sohib-code