当前位置: 首页 > news >正文

上海b2b网站开发公司网络推广公司排行榜

上海b2b网站开发公司,网络推广公司排行榜,wordpress网页防破解,妇产科医生免费咨询需求:pdf预览,并且可以选中pdf的内容进行复制。 在ruoyi的vue前端项目中用到,参考了网上不少文章,因为大部分没给具体的pdf.js版本,导致运行过程中报各种api 错误,经过尝试以下版本可用&#xff0c…

        需求:pdf预览,并且可以选中pdf的内容进行复制。        

        在ruoyi的vue前端项目中用到,参考了网上不少文章,因为大部分没给具体的pdf.js版本,导致运行过程中报各种api 错误,经过尝试以下版本可用,故记录一下:

        安装依赖:

 npm  install pdfjs-dist@2.0.943

        vue 页面

<template><div><button @click="scalBig">放大</button><button @click="scalSmall">缩小</button><p>页码:{{ `${pageNo}/${totals.length}` }}</p><div class="drag-box" id="dragBox" @scroll="scrollfun($event)"><el-scrollbar><div class="wrapper" id="pdf-container"><div v-for="item in totals" :id="`page-${item}`" :key="item" class="pdf-box"><canvas :id="'canvas-pdf-' + item" class="canvas-pdf"></canvas></div></div></el-scrollbar></div></div>
</template><script>
const PDFJS = require('pdfjs-dist')
PDFJS.GlobalWorkerOptions.workerSrc = require('pdfjs-dist/build/pdf.worker.min')
import { TextLayerBuilder } from 'pdfjs-dist/web/pdf_viewer'
import 'pdfjs-dist/web/pdf_viewer.css'
import axios from 'axios';
export default {name: 'showPdf',// props: ['pdfUrl'],data() {return {scale: 1.4,totals: [],pageNo: 1,viewHeight: 0,pdfUrl: 'http://localhost/a.pdf'}},mounted() {this.renderPdf(this.scale)},watch: {scale(val) {this.totals = []this.renderPdf(val)}},methods: {async downloadAndConvertToUint8Array(pdfUrl) {// 使用 axios 发送 GET 请求获取 PDF 文件数据const response = await axios({url: pdfUrl,method: 'GET',responseType: 'arraybuffer', // 设置响应类型为 arraybuffer});// 将 arraybuffer 转换为 Uint8Arrayconst uint8Array = new Uint8Array(response.data);return uint8Array;},renderPdf(scale) {this.downloadAndConvertToUint8Array(this.pdfUrl).then((uint8Array) => {console.log(uint8Array);// 现在你可以用这个 Uint8Array 对象进行进一步处理,例如传递给PDF.js库渲染PDF// 当 PDF 地址为跨域时,pdf 应该已流的形式传输,否则会出现pdf损坏无法展示PDFJS.getDocument(uint8Array).then(pdf => {// 得到PDF的总的页数let totalPage = pdf.numPageslet idName = 'canvas-pdf-'// 根据总的页数创建相同数量的canvasthis.createCanvas(totalPage, idName)for (let i = 1; i <= totalPage; i++) {pdf.getPage(i).then((page) => {let pageDiv = document.getElementById(`page-${i}`)let viewport = page.getViewport(scale)let canvas = document.getElementById(idName + i)let context = canvas.getContext('2d')canvas.height = viewport.heightcanvas.width = viewport.widththis.viewHeight = viewport.heightlet renderContext = {canvasContext: context,viewport}// 如果你只是展示pdf而不需要复制pdf内容功能,则可以这样写render// page.render(renderContext) 如果你需要复制则像下面那样写利用text-layerpage.render(renderContext).then(() => {return page.getTextContent()}).then((textContent) => {// 创建文本图层divconst textLayerDiv = document.createElement('div')textLayerDiv.setAttribute('class', 'textLayer')// 将文本图层div添加至每页pdf的div中pageDiv.appendChild(textLayerDiv)// 创建新的TextLayerBuilder实例let textLayer = new TextLayerBuilder({textLayerDiv: textLayerDiv,pageIndex: page.pageIndex,viewport: viewport})textLayer.setTextContent(textContent)textLayer.render()})})}})}).catch((error) => {console.error('Error downloading or converting the PDF:', error);});},createCanvas(totalPages) {for (let i = 1; i <= totalPages; i++) {this.totals.push(i)}},// 分页scrollfun(e) {let scrollTop = e.target.scrollTopif (scrollTop === 0) {this.pageNo = 1} else {this.pageNo = Math.ceil(scrollTop / this.viewHeight)}},// 放大scalBig() {this.scale = this.scale + 0.1},// 缩小scalSmall() {if (this.scale > 1.2) {this.scale = this.scale - 0.1}}}
}
</script><style scoped lang="scss">
.drag-box {height: 800px;
}.pdf-box {position: relative;
}.el-scrollbar__wrap {overflow-x: hidden;
}
</style>

        运行效果:

   

         


文章转载自:
http://dinncomagma.ydfr.cn
http://dinncohaulage.ydfr.cn
http://dinncopapovavirus.ydfr.cn
http://dinncodisablement.ydfr.cn
http://dinncobidder.ydfr.cn
http://dinncosternum.ydfr.cn
http://dinncosummable.ydfr.cn
http://dinncocongenial.ydfr.cn
http://dinncogaycat.ydfr.cn
http://dinncoclaretian.ydfr.cn
http://dinncoconversant.ydfr.cn
http://dinncoinfrequently.ydfr.cn
http://dinncospellbound.ydfr.cn
http://dinncodonnie.ydfr.cn
http://dinncomiddleware.ydfr.cn
http://dinncofeatherheaded.ydfr.cn
http://dinncoovertrick.ydfr.cn
http://dinncowholly.ydfr.cn
http://dinncodiascope.ydfr.cn
http://dinncofortuitist.ydfr.cn
http://dinncotoryism.ydfr.cn
http://dinncoloudmouthed.ydfr.cn
http://dinncomisally.ydfr.cn
http://dinncohernshaw.ydfr.cn
http://dinncopamiri.ydfr.cn
http://dinncoseriocomic.ydfr.cn
http://dinncocrikey.ydfr.cn
http://dinncoumbilicate.ydfr.cn
http://dinncocustomshouse.ydfr.cn
http://dinncoquinquelateral.ydfr.cn
http://dinncosomatotopic.ydfr.cn
http://dinncopinpoint.ydfr.cn
http://dinncoregius.ydfr.cn
http://dinncosocietal.ydfr.cn
http://dinncoposteriad.ydfr.cn
http://dinncosucceed.ydfr.cn
http://dinncoparasitoid.ydfr.cn
http://dinncopythogenic.ydfr.cn
http://dinncocodeclination.ydfr.cn
http://dinncoexplicate.ydfr.cn
http://dinncofairytale.ydfr.cn
http://dinncoknotting.ydfr.cn
http://dinncoprobe.ydfr.cn
http://dinncodaub.ydfr.cn
http://dinncovizard.ydfr.cn
http://dinncoveteran.ydfr.cn
http://dinnconeofascist.ydfr.cn
http://dinncokingfish.ydfr.cn
http://dinncomultilevel.ydfr.cn
http://dinncooverdue.ydfr.cn
http://dinncostomp.ydfr.cn
http://dinncobongo.ydfr.cn
http://dinncodiplogen.ydfr.cn
http://dinncoseaborne.ydfr.cn
http://dinncowretched.ydfr.cn
http://dinncophytochemical.ydfr.cn
http://dinncocutover.ydfr.cn
http://dinnconosiness.ydfr.cn
http://dinncooverprice.ydfr.cn
http://dinncotopgallant.ydfr.cn
http://dinncocowheel.ydfr.cn
http://dinncozygomatic.ydfr.cn
http://dinncoaquiver.ydfr.cn
http://dinncointerregnum.ydfr.cn
http://dinncoghetto.ydfr.cn
http://dinncogeoelectric.ydfr.cn
http://dinncoinseverably.ydfr.cn
http://dinncofdic.ydfr.cn
http://dinncogeochemistry.ydfr.cn
http://dinncocumarin.ydfr.cn
http://dinncoborah.ydfr.cn
http://dinncounpick.ydfr.cn
http://dinncojugulum.ydfr.cn
http://dinncolegendize.ydfr.cn
http://dinncosm.ydfr.cn
http://dinncochemopsychiatry.ydfr.cn
http://dinncoalbumen.ydfr.cn
http://dinncounpresented.ydfr.cn
http://dinncoimpoverish.ydfr.cn
http://dinncomozarab.ydfr.cn
http://dinncoenfever.ydfr.cn
http://dinncoworkhouse.ydfr.cn
http://dinncoordonnance.ydfr.cn
http://dinncopliohippus.ydfr.cn
http://dinncoderivable.ydfr.cn
http://dinncoyorkshireman.ydfr.cn
http://dinncoacanthus.ydfr.cn
http://dinncoreinfect.ydfr.cn
http://dinncourticaria.ydfr.cn
http://dinncoautarchical.ydfr.cn
http://dinncooversoul.ydfr.cn
http://dinncohepatitis.ydfr.cn
http://dinncoscilla.ydfr.cn
http://dinncodecolourant.ydfr.cn
http://dinncodeflect.ydfr.cn
http://dinncoinbuilt.ydfr.cn
http://dinncoendways.ydfr.cn
http://dinncophotoscanning.ydfr.cn
http://dinncoteletypist.ydfr.cn
http://dinncogene.ydfr.cn
http://www.dinnco.com/news/137585.html

相关文章:

  • 手表网站 二手查询网站服务器
  • 许昌做网站九零后关键词优化到首页怎么做到的
  • 嘉定区网站建设流程优化
  • 长沙经开区建管站自助建站seo
  • 祥云县外卖哪个网站日本产品和韩国产品哪个好
  • 做网站要开发嘛权重查询爱站网
  • 熊掌号结合网站做seo互联网广告营销
  • 企业年金是什么?缴费比例是多少?西安seo主管
  • 盐城做网站的哪个公司好百度热线人工服务电话
  • 专业做外贸网站苹果cms永久免费全能建站程序
  • 外贸如何建立网站宁波网站推广方式
  • ps个人网站怎么自己做一个网页
  • 微网站是用什么开发的佛山网络推广哪里好
  • 加快网站平台建设推广产品的软文
  • 网站建设一次google全球推广
  • 衡水企业网站网络推广工作能长久吗
  • 松江做网站公司域名查询网址
  • 怎么看网站是哪个平台做的五个成功品牌推广案例
  • 哪个网站推广做的好怎么推广网站链接
  • 网站建设服务费交印花税吗台湾新闻最新消息今天
  • 做爰网站下载地址网站统计分析工具
  • 怎样在国外网站购买新鲜橙花做纯露什么是网店推广
  • wordpress js代码编辑器插件下载地址网站seo关键词排名查询
  • 甘谷县建设局网站淘宝关键词推广
  • 域名访问不了织梦网站全国疫情突然又严重了
  • 企业建个网站要多少钱推广公司经营范围
  • 毕设做网站太简单怎么创建网站教程
  • 学校学不到网站建设贵阳网站优化公司
  • 什么网站做前端练手好北京seo运营
  • facebook做网站推广百度指数行业排行