当前位置:网站首页>PDF Online preview, use of pdf.js
PDF Online preview, use of pdf.js
2022-07-23 12:46:00 【Monster in the North Sea】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../plugins/pdfjs/pdf.min.js" ></script>
<script src="../plugins/pdfjs/pdf.worker.min.js" ></script>
<!-- These two plug-ins are in the resources , You can also go to the official website by yourself , The version I use is relatively low , yes 2.0.X Of , I forgot the specific version number , The higher the version, the higher the version requirements for the browser -->
</head>
<body>
<div id="pdfDiv"></div>
<script> // Exhibition pdf function initPdf(url) {
var loadingTask = pdfjsLib.getDocument(url); var pdfDiv = document.getElementById('pdfDiv');// there pdfDiv And the above container id Corresponding loadingTask.promise.then(function (pdf) {
for (var i = 1; i <= pdf.numPages; i++) {
pdf.getPage(i).then(function (page) {
var scale = 1.5; var viewport = page.getViewport({
scale: scale,}); // Support HiDPI-screens. var outputScale = window.devicePixelRatio || 1; var canvas = document.createElement('canvas'); var context = canvas.getContext('2d'); pdfDiv.appendChild(canvas); canvas.width = Math.floor(viewport.width * outputScale); canvas.height = Math.floor(viewport.height * outputScale); canvas.style.width = Math.floor(viewport.width) + "px"; canvas.style.height = Math.floor(viewport.height) + "px"; var transform = outputScale !== 1 ? [outputScale, 0, 0, outputScale, 0, 0] : null; var renderContext = {
canvasContext: context, transform: transform, viewport: viewport }; page.render(renderContext); }); } }); } var filePath = ' It can be a local file path , It can also be a network file path '; initPdf(filePath);// filePath Is for preview pdf Address ,D:\nginx-1.21.1\html\fzzd\resource\articleFile\20220420\053129003.pdf </script>
</body>
</html>
边栏推荐
猜你喜欢
![[memory understand the difference and function between ram flash and EEPROM memory]](/img/71/c9ada89e0a876e0581a7b5ceec2bff.png)
[memory understand the difference and function between ram flash and EEPROM memory]

C# 自定义Queue队列集合

LSM-tree(Log Structured-Merge Tree)的理解

Hcip--- BGP related configuration

C语言数据库:详细的说明用学生管理系统了解数据库的操作,简单易懂。

Unity3D高清渲染管线无法在模型上播放视频

Unity在URP管线下使用TriLib插件加载模型材质不正确的问题

C语言也能写植物大战僵尸

Unity3d:UGUI,UI与特效粒子层级,2018.2以上版本BakeMesh,粒子在两个Image之间且在ScrollView
![[AUTOSAR storage stack NVM]](/img/7a/15e01f8ace647b55e11e764dba1b64.png)
[AUTOSAR storage stack NVM]
随机推荐
hot 100深度优先
第一类错误离我们有多远
【无标题】
C语言:基于顺序表的学生管理系统,超级详细,全部都有注释,看完不懂来扇我。
Prometheus Operator使用指南笔记
详解TCP连接的建立
Hcip--- BGP related configuration
详解TCP的交互数据流和成块数据流
HCIP---条件匹配和OSPF协议
如何用普通的文本编辑器写Web页面
Unity shader missing problem
广播,组播,单播
Configure TX1 system + set to solid-state disk startup
浅析互联网协议(二)
浅析UDP协议和TCP协议
HCIP-HCIA知识回顾(二)
第一篇试水--*offer
RPM build 已经安装了依赖包但还是报错没有包中提供的模块
直白理解一文搞定http协议缓存
Mutual implementation of queue and heap (pure C implementation)