pdf.js使用步骤

使用pdfjs 网页在线预览需要后端服务器支持

1、下载PDF.js 源码包

地址:PDF.js

2、解压源码包,将源码包放置到后端服务器

3、后端部署完成后 访问 viewer.html

类似上图

4、访问在线pdf文件

http://localhost:8081/web/viewer.html?file=xxxx.pdf

使用file=你的在线的pdf文件路径就可以了

如果出现以下问题

viewer.mjs:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.

pdf.mjs:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.

说明无法解析.mjs 文件格式

解决方法

把mjs 的后缀改成js 或者 .htaccess 添加

<IfModule mod_mime.c>

AddType application//javascript js mjs

</IfModule>

如果发现存在跨域问题

找到viewer.mjs

将上面的代码注释即可。

相关推荐
z落落9 分钟前
C#WinForm控件实战:Panel与单选框动态创建
开发语言·c#
ptc学习者9 分钟前
python 中描述符@property property 大概的样子
开发语言·python
zmzb010311 分钟前
Python课后习题训练记录Day129
开发语言·python
张忠琳19 分钟前
【Go 1.26.4】Golang Map 深度解析
开发语言·后端·golang
Vertira20 分钟前
如何对QT开发的软件进行打包[已解决]
开发语言·qt
AI人工智能+电脑小能手22 分钟前
【大白话说Java面试题 第110题】【并发篇】第10题:CAS 存在哪些问题?
java·开发语言·面试
石一峰69930 分钟前
C 语言函数设计模式实战经验
c语言·开发语言·设计模式
sitellla36 分钟前
Pydub:用 Python 处理音频,不写废话
开发语言·python·其他·音视频
xingyuzhisuan1 小时前
缓存命中率提升方案:从 30% 优化至 82% 全流程优化记录
java·开发语言·缓存·ai
郑洁文1 小时前
基于Python的恶意流量监测系统的设计与实现
开发语言·python