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

网站图标怎么下载有哪些做短租的网站

网站图标怎么下载,有哪些做短租的网站,wordpress 友情链接小工具,如何申请域名建网站准备做的系统中出现了 想导出当前页面的png或者pdf设计数据较多后端做可能比较麻烦 就自己研究了一下 1、安装html2canvas 、jspdf包 npm install --save html2canvas // 可以将dom元素转为一张图片 npm install --save jspdf // 导出为PDF格式 2、vue组件中引用&#x…

准备做的系统中出现了 想导出当前页面的png或者pdf设计数据较多后端做可能比较麻烦 就自己研究了一下

1、安装html2canvas 、jspdf包

npm install --save html2canvas   // 可以将dom元素转为一张图片
npm install --save jspdf   // 导出为PDF格式

2、vue组件中引用,代码如下:

<template><div class="content"><a-button @click="exportPNG" size="small" type="primary">导出PNG</a-button><a-button @click="exportPDF" size="small" type="primary">导出PDF</a-button><div id="main-charts">需要截取的内容区域我想测试导出是否可行</div></div>
</template>

3、导出png

<script lang="ts" setup>// 引入插件import html2canvas from 'html2canvas';import jsPDF from 'jspdf';// 导出pngconst exportPNG = () => {const ele: HTMLElement | null = document.getElementById('main-charts');html2canvas(ele as HTMLElement).then((canvas: any) => {const contentWidth = canvas.width;const contentHeight = canvas.height;const ctx: any = canvas.getContext('2d');// 添加水印ctx.textAlign = 'center';ctx.textBaseline = 'middle';ctx.rotate((25 * Math.PI) / 180);ctx.font = '20px Microsoft Yahei';ctx.fillStyle = 'rgba(184, 184, 184, 0.8)';for (let i = contentWidth * -1; i < contentWidth; i += 240) {for (let j = contentHeight * -1; j < contentHeight; j += 100) {// 填充文字,x 间距, y 间距ctx.fillText('水印名', i, j);}}const imgUrl = canvas.toDataURL('image/png');const tempLink = document.createElement('a'); // 创建一个a标签tempLink.style.display = 'none';tempLink.href = imgUrl;tempLink.setAttribute('download', '文件名'); // 给a标签添加下载属性if (typeof tempLink.download === 'undefined') {tempLink.setAttribute('target', '_blank');}document.body.appendChild(tempLink); // 将a标签添加到body当中tempLink.click(); // 启动下载document.body.removeChild(tempLink); // 下载完毕删除a标签window.URL.revokeObjectURL(imgUrl);})}
</script>

4、导出pdf

<script lang="ts" setup>// 引入插件import html2canvas from 'html2canvas';import jsPDF from 'jspdf';const exportPDF = () => {const ele: HTMLElement | null = document.getElementById('main-charts');html2canvas(ele as HTMLElement, {dpi: 96, // 分辨率scale: 2, // 设置缩放useCORS: true, // 允许canvas画布内 可以跨域请求外部链接图片, 允许跨域请求。,// backgroundColor:'#ffffff',这样背景还是黑的bgcolor: '#ffffff', // 应该这样写logging: false, // 打印日志用的 可以不加默认为false}).then((canvas) => {const contentWidth = canvas.width;const contentHeight = canvas.height;// 一页pdf显示html页面生成的canvas高度;const pageHeight = (contentWidth / 592.28) * 841.89;// 未生成pdf的html页面高度let leftHeight = contentHeight;// 页面偏移let position = 0;// a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高const imgWidth = 595.28;const imgHeight = (595.28 / contentWidth) * contentHeight;const ctx: any = canvas.getContext('2d');// 添加水印ctx.textAlign = 'center';ctx.textBaseline = 'middle';ctx.rotate((25 * Math.PI) / 180);ctx.font = '20px Microsoft Yahei';ctx.fillStyle = 'rgba(184, 184, 184, 0.8)';for (let i = contentWidth * -1; i < contentWidth; i += 240) {for (let j = contentHeight * -1; j < contentHeight; j += 100) {// 填充文字,x 间距, y 间距ctx.fillText('水印名', i, j);}}const pageData = canvas.toDataURL('image/jpeg', 1.0);const pdf = new jsPDF('', 'pt', 'a4');if (leftHeight < pageHeight) {// 在pdf.addImage(pageData, 'JPEG', 左,上,宽度,高度)设置在pdf中显示;pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);} else {// 分页while (leftHeight > 0) {pdf.addImage(pageData,'JPEG',0,position,imgWidth,imgHeight);leftHeight -= pageHeight;position -= 841.89;// 避免添加空白页if (leftHeight > 0) {pdf.addPage();}}}// 可动态生成pdf.save(`文件名.pdf`);});}
</script>

http://www.yayakq.cn/news/483662/

相关文章:

  • 网站建设为什么必须有服务器网站seo招聘
  • 淘宝网站建设策划书青岛路桥建设集团有限公司网站
  • 大型网站都怎么做推广上海地区网站开发公司
  • 有没有做门面设计的网站品牌网站建设价位
  • 长春专用网站建设wordpress 数据库权限
  • 网站百度未收录商桥安装显示网站改版 请示
  • 九江网站设计公司余江网站建设
  • 域名没备案如何建设网站网站备案网站名称
  • 昆明网站建设推广字节跳动员工待遇
  • 厦门正规网站建设多少龙华营销型网站建设公司
  • 中国建设监理协会网站网站设计简单吗
  • 烟台网站建设开发网络与设计是干嘛的
  • 怎么查看一个网站的后台如何在图片上做网站水印图
  • 免费 个人 网站广州优秀网站建设
  • 规划网站站点需要遵循哪些原则wordpress 转换成帝国
  • 网站 动画 怎么做的深圳保障性住房有哪些
  • 襄阳营销型网站建设刷东西网站怎么做
  • 高端制作网站公司内蒙古城乡建设厅网站资质公告
  • 网站建设与管理课程的目标深圳企业网站哪家强
  • 哪个网站做系统国内永久免费云服务器推荐
  • 网站优化专家18600119496古代中国建筑网站
  • 长沙教育网站开发江苏建设教育网站
  • 怎么做批量的网站检查手机网站制作报价
  • 加强医院微信和网站建设乐至seo
  • wordpress 下载网站国家建设工程信息网
  • 住房和城乡建设部网站个人简介网页怎么做
  • 网站建设用户调查报告网站为什么做子域名
  • 十大品牌网站wordpress高级模板下载
  • 上海建站模板搭建深圳优化猫
  • 做网站需注意事项门户