如何在Angular CLI应用程序中给pdf.js worker [英] How to give pdf.js worker in Angular CLI application
问题描述
出于某些pdf目的,我直接在angular应用程序中使用了pdf.js.效果很好.
I used pdf.js directly in angular app for some pdf purposes. It works fine.
我从pdfjs-dist中导入了pdfjs,而我的package.json中包含了pdfjs-dist.
I imported the pdfjs from the pdfjs-dist and my package.json includes pdfjs-dist.
我的pdf工作正常,但是在控制台中,出现以下错误.
My pdf is working fine, but in the console, I get the below error.
pdf.js:9067 GET http://localhost:4300/main.bundle.worker.js 404 (Not Found)
pdf.js:351 Warning: Setting up fake worker.
如何在角度CLI应用程序中正确设置工作程序?
How to set up the worker properly in angular CLI application?
推荐答案
我花了几天的时间解决了这个问题. 第一次赢得StackBlitz在线Angular6服务.但是在家里重复有一个问题.
I solved this issue with some days of fighting. First time I win with StackBlitz online Angular6 service. But had a problem with repeating at home.
就我而言,可以将Angular 6和CLI与本地文件一起使用. PS:当您使用本地安装的和工作程序并带有CDN等外部链接的工作程序时,请关心类似版本的pdf.js和pdf.worker.js(我使用pdf.worker.min.js).
In my case it is possible to use with Angular 6 and CLI with local file. PS: Care about similar versions of pdf.js and pdf.worker.js (I use pdf.worker.min.js) when you use local installed and worker with external link like CDN and etc.
我需要从CDN https://www.jsdelivr中获得的版本. com/package/npm/pdfjs-dist?path = build
将您的pdf.worker.js或pdf.worker.min.js放入/src/assets/ 然后使用:
Put your pdf.worker.js or pdf.worker.min.js to /src/assets/ And then use:
import * as pdfjsLib from 'pdfjs-dist/build/pdf
pdfjsLib.GlobalWorkerOptions.workerSrc = './assets/pdf.worker.min.js';
规格: 带有命令"ng version"
Specifications: got with command 'ng version'
Angular CLI: 6.0.3
Node: 8.10.0
OS: linux x64
Angular: 6.0.2
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.3
@angular-devkit/build-angular 0.6.3
@angular-devkit/build-optimizer 0.6.3
@angular-devkit/core 0.6.3
@angular-devkit/schematics 0.6.3
@angular/cli 6.0.3
@ngtools/webpack 6.0.3
@schematics/angular 0.6.3
@schematics/update 0.6.3
rxjs 6.1.0
typescript 2.7.2
webpack 4.8.3
这篇关于如何在Angular CLI应用程序中给pdf.js worker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!