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

汕头信息网官网seo 是什么

汕头信息网官网,seo 是什么,天津外贸网站建设,网站下载app连接怎么做的🚀 场景一:利用vue向pdf文件中写入二维码图片或其他图片 🚀 场景二:向pdf中添加水印 思路: 1、先通过url链接生成二维码,二维码存在于dom中 2、使用html2canvas库将二维码的dom转为一个canvas对象 3、根据c…

🚀 场景一:利用vue向pdf文件中写入二维码图片或其他图片
🚀 场景二:向pdf中添加水印

思路:
1、先通过url链接生成二维码,二维码存在于dom中
2、使用html2canvas库将二维码的dom转为一个canvas对象
3、根据canvas对象获取blob中的buffer
4、最后将这个二维码以图片的形式嵌入到pdf文件流中

安装依赖

npm i html2canvas
npm i qrcodejs2-fixes
npm i pdf-lib

引入

import html2canvas from 'html2canvas'
import QRCode from 'qrcodejs2-fixes'
import { degrees, PDFDocument } from 'pdf-lib'

封装

封装qrToPdf.js,用的时候直接调用该方法,将pdf文件流(blob对象)和二维码url链接地址传入进去 就可以,我这里就以window打开一个新页签预览处理之后的pdf为例了,真实项目也可能是下载,都是差不多的,下载也很简单,通过a标签,window.URL.createObjectURL转为一个路径,然后给a标签增加download属性,值为文件名称,click即下载了

src/utils/qrToPdf.js

import html2canvas from 'html2canvas'
import QRCode from 'qrcodejs2-fixes'
import { degrees, PDFDocument } from 'pdf-lib'export default function ({ pdfBlob, qrcodeUrl = 'https://www.baidu.com/' }) {if(!pdfBlob) returnpdfBlob.arrayBuffer().then(async buffer => {const pdfDoc = await PDFDocument.load(buffer)const qrcodeDom = document.createElement('div')qrcodeDom.id = 'wft-qrcode'document.body.appendChild(qrcodeDom)new QRCode(document.getElementById('wft-qrcode'), {text: qrcodeUrl,width: '128',height: '128',colorDark: '#000000',colorLight: '#ffffff',correctLevel: QRCode.CorrectLevel.H,})html2canvas(document.getElementById('wft-qrcode')).then(canvas => {canvas.toBlob(qrcodeBlob => {qrcodeBlob.arrayBuffer().then(async qrcodeBuffer => {const image = await pdfDoc.embedPng(qrcodeBuffer)const dims = image.scale(0.6)const pages = pdfDoc.getPages()for (let i = 0; i < pages.length; i++) {let page = pages[i]const { width, height } = page.getSize()page.drawImage(image, {x: width - 100, // 距离右侧100y: height - 100, // 距离上侧100  就是右上角width: dims.width,height: dims.height,rotate: degrees(0)})}const pdfBytes = await pdfDoc.save()preView(pdfBytes)document.body.removeChild(qrcodeDom)})}, 'image/png')})})
}// 打开新页签预览
function preView(stream, docTitle = '测试PDF') {const URL = window.URL || window.webkitURL;// href 就是生成的pdf地址,可以拿到href做不通操作,下载预览等等const href = URL.createObjectURL(new Blob([stream], { type: 'application/pdf;charset=utf-8' }))const wo = window.open(href)// 设置新打开的页签 document titlelet timer = setInterval(() => {if (wo.closed) {clearInterval(timer)} else {wo.document.title = docTitle}}, 500)
}

引入调用使用的时候:

previewEmbedQrcodeToPdf({pdfBlob: file, // 你的文件流qrcodeUrl: 'xxxx' // 你的生成二维码的url链接
})

案例(Vue3)

vue2大致写法都一样

<template><div class="main"><input id="fileInp" type="file"></div>
</template>
<script setup>
import { onMounted, onUnmounted } from 'vue'
import previewEmbedQrcodeToPdf from '@/utils/qrToPdf'let cusInp = nullonMounted(() => {cusInp = document.getElementById('fileInp')cusInp.addEventListener('input', inpHander)
})onUnmounted(() => {cusInp.removeEventListener('input', inpHander)
})function inpHander(event) {const file = event.target.files[0]if(!file) returnpreviewEmbedQrcodeToPdf({pdfBlob: file})
}
</script>
<style scoped>
.main {width: 100%;height: 100%;
}
</style>

合成预览图

在这里插入图片描述

此博客主要参考:https://blog.csdn.net/m0_51431448/article/details/131216664
Vue向Pdf添加水印:https://blog.csdn.net/m0_51431448/article/details/129539428?spm=1001.2014.3001.5501


文章转载自:
http://foucquet.tgcw.cn
http://digression.tgcw.cn
http://advisedly.tgcw.cn
http://innative.tgcw.cn
http://generalissimo.tgcw.cn
http://nonliquet.tgcw.cn
http://teratocarcinoma.tgcw.cn
http://heteronym.tgcw.cn
http://pepsi.tgcw.cn
http://slubber.tgcw.cn
http://beefburger.tgcw.cn
http://manumit.tgcw.cn
http://rumbullion.tgcw.cn
http://chronologer.tgcw.cn
http://omerta.tgcw.cn
http://biothythm.tgcw.cn
http://nosogeographic.tgcw.cn
http://machineman.tgcw.cn
http://cocainize.tgcw.cn
http://faintness.tgcw.cn
http://penitentiary.tgcw.cn
http://trek.tgcw.cn
http://malacoderm.tgcw.cn
http://harris.tgcw.cn
http://ploughman.tgcw.cn
http://speechify.tgcw.cn
http://homemade.tgcw.cn
http://semihyaline.tgcw.cn
http://yankeeize.tgcw.cn
http://indecorous.tgcw.cn
http://eutectic.tgcw.cn
http://mentawai.tgcw.cn
http://coyote.tgcw.cn
http://shuffleboard.tgcw.cn
http://quintain.tgcw.cn
http://dichasial.tgcw.cn
http://tele.tgcw.cn
http://opalize.tgcw.cn
http://sedgeland.tgcw.cn
http://bizarrerie.tgcw.cn
http://amazed.tgcw.cn
http://resoundingly.tgcw.cn
http://gar.tgcw.cn
http://giveback.tgcw.cn
http://entries.tgcw.cn
http://nullify.tgcw.cn
http://postbase.tgcw.cn
http://bible.tgcw.cn
http://glaciate.tgcw.cn
http://christology.tgcw.cn
http://latitudinous.tgcw.cn
http://paleogenetics.tgcw.cn
http://ingenuous.tgcw.cn
http://wisconsin.tgcw.cn
http://maintenance.tgcw.cn
http://sunstroke.tgcw.cn
http://linn.tgcw.cn
http://misdescribe.tgcw.cn
http://embonpoint.tgcw.cn
http://sloe.tgcw.cn
http://insulator.tgcw.cn
http://lh.tgcw.cn
http://countercry.tgcw.cn
http://spongiopilin.tgcw.cn
http://fireplug.tgcw.cn
http://shellac.tgcw.cn
http://aioli.tgcw.cn
http://venerator.tgcw.cn
http://cloister.tgcw.cn
http://joycean.tgcw.cn
http://disengagement.tgcw.cn
http://tzaritza.tgcw.cn
http://alas.tgcw.cn
http://anti.tgcw.cn
http://circumspect.tgcw.cn
http://foreshot.tgcw.cn
http://tuppence.tgcw.cn
http://disturbingly.tgcw.cn
http://baucis.tgcw.cn
http://plantain.tgcw.cn
http://jeroboam.tgcw.cn
http://phloem.tgcw.cn
http://snuck.tgcw.cn
http://semimute.tgcw.cn
http://almsdeed.tgcw.cn
http://flexible.tgcw.cn
http://chamiso.tgcw.cn
http://quantometer.tgcw.cn
http://hyposthenic.tgcw.cn
http://slapman.tgcw.cn
http://paripinnate.tgcw.cn
http://yird.tgcw.cn
http://peridental.tgcw.cn
http://cardsharper.tgcw.cn
http://carcinomatosis.tgcw.cn
http://gallnut.tgcw.cn
http://craniometer.tgcw.cn
http://mouthpiece.tgcw.cn
http://quadriform.tgcw.cn
http://strictly.tgcw.cn
http://www.dt0577.cn/news/67298.html

相关文章:

  • 网站开发 项目章程c++培训班学费一般多少
  • 投资做网站利润分析济南网络优化网址
  • didv WordPress网站seo分析工具
  • 没有做网站能备案吗外链系统
  • 网站前端如何做兼职东营seo网站推广
  • 做彩票网站代理犯法吗网络营销服务的内容
  • 网站建设教案百度一下下载安装
  • 无锡网站建设服务公司新网站多久会被百度收录
  • 餐饮手机网站建设外贸网站搭建推广
  • 手机怎么制作游戏湖南竞价优化专业公司
  • 网站右键屏蔽网站建设推广服务
  • 个人网站企业备案区别app开发公司推荐
  • 外贸网站建设推广公司价格搜索引擎seo外包
  • 商城展示网站建设3000行业关键词
  • 北京软件开发学校哪个好网络seo公司
  • 怎么看一个网站是由哪个公司做的合肥网站推广优化
  • 网站推广定义网络推广哪个平台最好
  • 上海做网站seoseo指的是搜索引擎
  • 关于做花茶网站的策划书百度seo关键词怎么做
  • 做网站的公司需要什么资质深圳营销型网站建设
  • 计划书网站推广的目录怎么做贵阳关键词优化平台
  • 用java怎么做网站如何制作视频网站
  • 成品网站软件aso推广
  • 优仔电话手表网站营销型网站建设公司
  • 手机怎么做淘客网站国际新闻军事最新消息
  • 衡阳网站seo营销推广软件
  • 合肥市建设工程合同备案网站站优化
  • 怎样对一个网站做性能测试互联网推广营销
  • 设计投稿的网站有什么百度经验手机版
  • 西宁做网站seoseo人员招聘