Comments (14)
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.
try import the no worker vue file
import pdf from 'vue-pdf/src/vuePdfNoSssNoWorker'
from vue-pdf.
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.
@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.
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.
@Dd-ouni 按@dante2359 的做法可以
from vue-pdf.
from vue-pdf.
Is the packaging method wrong?
from vue-pdf.
got it!!
Modify the file in node_modules and compile
from vue-pdf.
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.
@chsword Where did you add the above code? Thanks
from vue-pdf.
@Dd-ouni 按@dante2359 的做法可以
@JakeWoki 好的,JakeWoki,谢谢!
from vue-pdf.
use this need worker-loader 2.0.0
from vue-pdf.
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)
- 微前端子应用加载 vue-pdf 时报跨域问题 HOT 2
- PDF切换页面的时候会一闪一闪的,体验很差
- pdf 渲染高度超出屏幕范围,怎么查看屏幕之外的部分
- 项目引入vue-pdf
- pdfRender.cancel().catch(function(err) , undefined (reading 'catch')" HOT 4
- TrueType Collection does not contain "DCWGQU+CambriaMath" font.
- when the window.devicePixelRatio less than 1,the pdf is vague.
- 、
- vue2 + vite require is not defined
- vue2项目编译报错 HOT 2
- 已解决print后字体乱码问题 HOT 1
- 改变视图大小,拖拉窗口会报错
- 使用插件时而出现跨域问题 HOT 1
- 预览带印章的那页,印章展示是不透明的,源文件是透明的,How to fix it!!!!
- pdf花屏:大部分文件正常展示,只有个别文件有问题,如图,有遇到的大佬看到,给个思路。 HOT 2
- 抱歉,未找到浏览器 Sorry, browser not found
- 与@vue/cli-service 5.x 不兼容 HOT 3
- pdf不能预览PDF的电子发票,比如打车发票
- vue-pdf突然不能用了,是跨域了?
- 请问支持VUE3吗 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-pdf.