当前位置:网站首页>pdf. JS introduction
pdf. JS introduction
2022-07-26 01:45:00 【Brick dog - Xiaoqiang】
Project background
Load and display... In the web page PDF Documents are the most common business requirements . Most browsers now come with pdf Preview function , But for every browser pdf Loaders are different , Toolbars cannot be customized , To unify different browsers pdf Consistency of Preview , And add some custom functions , We use pdf.js To achieve pdf Preview of .
pdf.js It's a very good pdf Parsing tool , In fact, our Firefox browser kernel comes with pdf The preview parser is pdf.js This parser , We put pdf Open in Firefox and press F12 You can see the content of the source code .

The following is the final effect of the project , Only the print button is left in the toolbar on the right , And trigger the events required by the project when printing , Prevent copying and downloading pdf.

pdf.js Use
Official website address :http://mozilla.github.io/pdf.js, Download the stable version

Project structure

Project use
Deploy the project to nginx perhaps IIS, Access... Directly in the browser viewer.html You can preview our pdf, How to use it is as follows ,file For what we want to preview pdf File address .
127.0.0.1/pdfjs-2.14.305-dist/web/viewer.html?file=/pdfjs-2.14.305-dist/web/compressed.tracemonkey-pldi-09.pdf
Project customization
We need to remove many unnecessary buttons from the toolbar on the right , And edit the button event , We can use PDFViewerApplication Object .
window.onload = function () {
PDFViewerApplication.appConfig.toolbar.presentationModeButton.classList.add("hidden");
PDFViewerApplication.appConfig.toolbar.openFile.classList.add("hidden");
PDFViewerApplication.appConfig.toolbar.download.classList.add("hidden");
PDFViewerApplication.appConfig.toolbar.viewBookmark.classList.add("hidden");
}
function onbeforeprint() {
var url = GetQuery1("file");
var urlParams = parseUrlParams(url);
$.ajax({
type: "get",
url: "/PrintCount?sCardNos=" + urlParams.sCardNos,
success: function (data) { }
});
}
window.addEventListener("beforeprint", onbeforeprint);Project deployment
IIS Deployment needs to be increased MIME type .properties text/plain

other
Prohibit automatic printing during preview , stay viewer.js Method _updateFromSandbox Comment out the following code .

边栏推荐
- Big view +500 cases, software teams should improve R & D efficiency in this way
- proto转换Dart | 项目使用Protobuf | flutter 使用grpc
- Recommend a super good UI automation tool: uiautomator2!
- CPU的三种模式
- Network performance evaluation tool ping/mtr
- Mysql_ Note1
- NFT market also began to diversify
- Test questions and answers of the latest Beijing Construction eight (materialman) mock examination in 2022
- zeromq浅析
- Network layer 2 and layer 3 forwarding
猜你喜欢

Typora expiration solution, what if typora can't open

SVN版本控制分支、合并功能使用

网络之IP地址

【Verilog数字系统设计(夏宇闻)4-----Verilog语法的基本概念2】

两阶段提交和三阶段提交

Easyrecovery15 data recovery software with high recovery rate and high download volume

餐饮连锁门店重塑增长背后的数字化转型
![[unity] random generation of two-dimensional cave map](/img/ec/7433f6e942fc3d0b03cac37ac87e7b.png)
[unity] random generation of two-dimensional cave map
![[Unity] 二维洞穴地图随机生成](/img/ec/7433f6e942fc3d0b03cac37ac87e7b.png)
[Unity] 二维洞穴地图随机生成

Recommend a super good UI automation tool: uiautomator2!
随机推荐
The sales volume has won the championship repeatedly. Is the secret of Wuling's success only low price?
Handler message mechanism - FWK layer
leetcode/只出现一次的数字
What is a test case? How to design?
I just test it
Huawei wireless device WDS configuration command
Kubernetes pod start process
PtGui pro12 vertical line correction
Dot screen precautions
2022年最新北京建筑八大员(材料员)模拟考试试题及答案
I want to know how much the Commission is for opening an account. Is it safe to open an account on your mobile phone
C语言中的整型数据类型(你真的了解吗)
Integer data type in C language (do you really understand it)
TV software burning
餐饮连锁门店重塑增长背后的数字化转型
y77.第四章 Prometheus大厂监控体系及实战 -- prometheus的服务发现机制(八)
Zombie's treasure test (enumeration)
Basic version of Google browser debugging tool (I)
Quickly create a topic folder
8. Learn Mysql to create data tables