Giter VIP home page Giter VIP logo

Comments (14)

FranckFreiburger avatar FranckFreiburger commented on June 12, 2024 5

In the file pdf.vue

try to replace

if ( process.env.VUE_ENV === 'server' ) {

	var PDFJS = require('pdfjs-dist/build/pdf.js');
	PDFJS.PDFJS.disableWorker = true;
} else {

	var PDFJS = require('pdfjs-dist/webpack.js');
}

with

var PDFJS = require('pdfjs-dist/build/pdf.js');
PDFJS.PDFJS.disableWorker = true;

and compile again

from vue-pdf.

chenxxzhe avatar chenxxzhe commented on June 12, 2024 4

try import the no worker vue file
import pdf from 'vue-pdf/src/vuePdfNoSssNoWorker'

from vue-pdf.

dante2359 avatar dante2359 commented on June 12, 2024 4

My goal was to exclude the file "[hash] .worker.js" from the root of the project. But, when I tried to use
import pdf from 'vue-pdf/src/vuePdfNoSssNoWorker'
instead of
import pdf from 'vue-pdf/src/vuePdfNoSss'
the PDF pages did not render without pdf.worker.

The following configuration helped me.
In 'vuePdfNoSss.vue':
comment string:
// var PdfjsWorker = require('worker-loader!pdfjs-dist/build/pdf.worker.js');
and add to top level:
import PdfjsWorker from 'pdfjs-dist/build/pdf.worker.js'

This will allow the custom configuration of 'worker-loader' from 'webpack' (in detail: https://webpack.js.org/loaders/worker-loader/).

And in 'vue.config.js' you need to define rule for 'worker.js' files in chainWebpack(config):

module.exports = {
  
  chainWebpack(config) {    
    config.module
      .rule('worker')
      .test(/\.worker\.js$/)
      .use('worker-loader').loader('worker-loader')
      .options(
        {
          inline: true,
          fallback: false
        }
        )
      .end()
  }
}

from vue-pdf.

chsword avatar chsword commented on June 12, 2024 4

@metadeck
vuePdfNoSss.vue

  if (
    typeof window !== "undefined" &&
    "Worker" in window &&
    navigator.appVersion.indexOf("MSIE 10") === -1
  ) {
    PDFJS.GlobalWorkerOptions.workerSrc =
      "https://xxxx.com/pdfjs/2.3.200/pdf.worker.min.js";//I changed the original PDFJS.GlobalWorkerOptions.workerPort = new PdfjsWorker(); to this
  }

from vue-pdf.

oneMoreTime1357 avatar oneMoreTime1357 commented on June 12, 2024 2

My goal was to exclude the file "[hash] .worker.js" from the root of the project. But, when I tried to use
import pdf from 'vue-pdf/src/vuePdfNoSssNoWorker'
instead of
import pdf from 'vue-pdf/src/vuePdfNoSss'
the PDF pages did not render without pdf.worker.

The following configuration helped me.
In 'vuePdfNoSss.vue':
comment string:
// var PdfjsWorker = require('worker-loader!pdfjs-dist/build/pdf.worker.js');
and add to top level:
import PdfjsWorker from 'pdfjs-dist/build/pdf.worker.js'

This will allow the custom configuration of 'worker-loader' from 'webpack' (in detail: https://webpack.js.org/loaders/worker-loader/).

And in 'vue.config.js' you need to define rule for 'worker.js' files in chainWebpack(config):

module.exports = {
  
  chainWebpack(config) {    
    config.module
      .rule('worker')
      .test(/\.worker\.js$/)
      .use('worker-loader').loader('worker-loader')
      .options(
        {
          inline: true,
          fallback: false
        }
        )
      .end()
  }
}

use this need worker-loader 2.0.0

from vue-pdf.

JakeWoki avatar JakeWoki commented on June 12, 2024 1

@Dd-ouni 按@dante2359 的做法可以

from vue-pdf.

huhai0403 avatar huhai0403 commented on June 12, 2024

image

from vue-pdf.

huhai0403 avatar huhai0403 commented on June 12, 2024

Is the packaging method wrong?

from vue-pdf.

youngLyz avatar youngLyz commented on June 12, 2024

got it!!
Modify the file in node_modules and compile
image

image

from vue-pdf.

chsword avatar chsword commented on June 12, 2024

I encountered the same problem, but the cause of my problem was that I made a CDN site for the js/css files after the build, and the index.html domain did not change.

My final solution is to change the loading method of the pdf.worker.js .

    PDFJS.GlobalWorkerOptions.workerSrc =
      "https://cdn.mydomain.com/pdfjs/2.3.200/pdf.worker.min.js";

from vue-pdf.

metadeck avatar metadeck commented on June 12, 2024

@chsword Where did you add the above code? Thanks

from vue-pdf.

pupa91 avatar pupa91 commented on June 12, 2024

@Dd-ouni 按@dante2359 的做法可以

@JakeWoki 好的,JakeWoki,谢谢!

from vue-pdf.

pupa91 avatar pupa91 commented on June 12, 2024

use this need worker-loader 2.0.0

from vue-pdf.

zhanfeng-z avatar zhanfeng-z commented on June 12, 2024

My goal was to exclude the file "[hash] .worker.js" from the root of the project. But, when I tried to use
import pdf from 'vue-pdf/src/vuePdfNoSssNoWorker'
instead of
import pdf from 'vue-pdf/src/vuePdfNoSss'
the PDF pages did not render without pdf.worker.

The following configuration helped me.
In 'vuePdfNoSss.vue':
comment string:
// var PdfjsWorker = require('worker-loader!pdfjs-dist/build/pdf.worker.js');
and add to top level:
import PdfjsWorker from 'pdfjs-dist/build/pdf.worker.js'

This will allow the custom configuration of 'worker-loader' from 'webpack' (in detail: https://webpack.js.org/loaders/worker-loader/).

And in 'vue.config.js' you need to define rule for 'worker.js' files in chainWebpack(config):

module.exports = {
  
  chainWebpack(config) {    
    config.module
      .rule('worker')
      .test(/\.worker\.js$/)
      .use('worker-loader').loader('worker-loader')
      .options(
        {
          inline: true,
          fallback: false
        }
        )
      .end()
  }
}

Unfortunately, IE11 not work.
I solve the problem by changing import PdfjsWorker from 'pdfjs-dist/build/pdf.worker.js' to import PdfjsWorker from 'pdfjs-dist/es5/build/pdf.worker.js'.

from vue-pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.