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

广州网站建设加盟什么网站赚的钱最多

广州网站建设加盟,什么网站赚的钱最多,网站建设的费用估算,seo推广薪资ChatGPT解答#xff1a;JavaScript保存当前网页页面图片为pdf文件或者word文件#xff0c;前端用vue2#xff0c;给出详细的方案和代码 ChatGPTDemo Based on OpenAI API (gpt-3.5-turbo). JavaScript保存当前网页页面图片为pdf文件或者word文件#xff0c;前端用vue2JavaScript保存当前网页页面图片为pdf文件或者word文件前端用vue2给出详细的方案和代码 ChatGPTDemo Based on OpenAI API (gpt-3.5-turbo). JavaScript保存当前网页页面图片为pdf文件或者word文件前端用vue2给出详细的方案和代码保存当前网页页面图片为pdf文件或者word文件可以通过第三方库实现。 使用jsPDF库保存为pdf文件 jsPDF是一个用于生成PDF文件的JavaScript库。它可以在客户端浏览器中生成PDF文件也可以在服务器端使用Node.js生成PDF文件。 安装jsPDF库 npm install jspdf --save使用jsPDF库生成pdf文件 import jsPDF from jspdf// 获取页面元素 const element document.getElementById(pdf-content)// 将元素转换为canvas html2canvas(element).then(canvas {// 获取canvas宽高const contentWidth canvas.widthconst contentHeight canvas.height// 将canvas转换为图片数据const imgData canvas.toDataURL(image/png)// 设置pdf文件尺寸const pdfWidth contentWidth / 2.75const pdfHeight contentHeight / 2.75// 创建pdf实例const pdf new jsPDF(p, mm, [pdfWidth, pdfHeight])// 添加图片到pdf文件pdf.addImage(imgData, PNG, 0, 0, pdfWidth, pdfHeight)// 保存pdf文件pdf.save(filename.pdf) })使用html-docx-js库保存为word文件 html-docx-js是一个用于将HTML转换为Microsoft Word文档的JavaScript库。 安装html-docx-js库 npm install html-docx-js --save使用html-docx-js库生成word文件 import htmlDocx from html-docx-js// 获取页面元素 const element document.getElementById(word-content)// 将元素转换为html const htmlContent element.outerHTML// 将html转换为word文档 const wordContent htmlDocx.asBlob(htmlContent)// 保存word文件 saveAs(wordContent, filename.docx)注意需要引入FileSaver库才能使用saveAs方法保存文件。 完整代码如下 templatedivdiv idpdf-content!-- 页面内容 --/divbutton clicksavePdf保存为pdf文件/buttondiv idword-content!-- 页面内容 --/divbutton clicksaveWord保存为word文件/button/div /templatescript import jsPDF from jspdf import htmlDocx from html-docx-js import FileSaver from file-saverexport default {methods: {savePdf() {// 获取页面元素const element document.getElementById(pdf-content)// 将元素转换为canvashtml2canvas(element).then(canvas {// 获取canvas宽高const contentWidth canvas.widthconst contentHeight canvas.height// 将canvas转换为图片数据const imgData canvas.toDataURL(image/png)// 设置pdf文件尺寸const pdfWidth contentWidth / 2.75const pdfHeight contentHeight / 2.75// 创建pdf实例const pdf new jsPDF(p, mm, [pdfWidth, pdfHeight])// 添加图片到pdf文件pdf.addImage(imgData, PNG, 0, 0, pdfWidth, pdfHeight)// 保存pdf文件pdf.save(filename.pdf)})},saveWord() {// 获取页面元素const element document.getElementById(word-content)// 将元素转换为htmlconst htmlContent element.outerHTML// 将html转换为word文档const wordContent htmlDocx.asBlob(htmlContent)// 保存word文件FileSaver.saveAs(wordContent, filename.docx)}} } /script加入新功能点击按钮后用户选择保存路径后再保存 要实现在用户选择保存路径后再保存文件可以使用input typefile元素来让用户选择保存路径然后再将文件保存到用户选择的路径中。 修改代码如下 templatedivdiv idpdf-content!-- 页面内容 --/divbutton clicksavePdf保存为pdf文件/buttondiv idword-content!-- 页面内容 --/divbutton clicksaveWord保存为word文件/buttoninput reffileInput typefile styledisplay: none changesaveFile/div /templatescript import jsPDF from jspdf import htmlDocx from html-docx-js import FileSaver from file-saverexport default {methods: {savePdf() {// 获取页面元素const element document.getElementById(pdf-content)// 将元素转换为canvashtml2canvas(element).then(canvas {// 获取canvas宽高const contentWidth canvas.widthconst contentHeight canvas.height// 将canvas转换为图片数据const imgData canvas.toDataURL(image/png)// 设置pdf文件尺寸const pdfWidth contentWidth / 2.75const pdfHeight contentHeight / 2.75// 创建pdf实例const pdf new jsPDF(p, mm, [pdfWidth, pdfHeight])// 添加图片到pdf文件pdf.addImage(imgData, PNG, 0, 0, pdfWidth, pdfHeight)// 显示文件选择框this.$refs.fileInput.click()// 将pdf文件保存到用户选择的路径中this.fileContent pdf.output(blob)})},saveWord() {// 获取页面元素const element document.getElementById(word-content)// 将元素转换为htmlconst htmlContent element.outerHTML// 将html转换为word文档const wordContent htmlDocx.asBlob(htmlContent)// 显示文件选择框this.$refs.fileInput.click()// 将word文件保存到用户选择的路径中this.fileContent wordContent},saveFile() {// 获取用户选择的文件const file this.$refs.fileInput.files[0]// 如果用户取消选择则返回if (!file) {return}// 保存文件到用户选择的路径中FileSaver.saveAs(this.fileContent, file.name)}} } /script修改后点击保存按钮后会弹出文件选择框用户选择保存路径后再保存文件。 完整的vue文件的内容 下面是完整的Vue文件的内容 templatedivdiv idpdf-content!-- 页面内容 --/divbutton clicksavePdf保存为pdf文件/buttondiv idword-content!-- 页面内容 --/divbutton clicksaveWord保存为word文件/buttoninput reffileInput typefile styledisplay: none changesaveFile/div /templatescript import jsPDF from jspdf import htmlDocx from html-docx-js import FileSaver from file-saverexport default {data() {return {fileContent: null}},methods: {savePdf() {// 获取页面元素const element document.getElementById(pdf-content)// 将元素转换为canvashtml2canvas(element).then(canvas {// 获取canvas宽高const contentWidth canvas.widthconst contentHeight canvas.height// 将canvas转换为图片数据const imgData canvas.toDataURL(image/png)// 设置pdf文件尺寸const pdfWidth contentWidth / 2.75const pdfHeight contentHeight / 2.75// 创建pdf实例const pdf new jsPDF(p, mm, [pdfWidth, pdfHeight])// 添加图片到pdf文件pdf.addImage(imgData, PNG, 0, 0, pdfWidth, pdfHeight)// 显示文件选择框this.$refs.fileInput.click()// 将pdf文件保存到用户选择的路径中this.fileContent pdf.output(blob)})},saveWord() {// 获取页面元素const element document.getElementById(word-content)// 将元素转换为htmlconst htmlContent element.outerHTML// 将html转换为word文档const wordContent htmlDocx.asBlob(htmlContent)// 显示文件选择框this.$refs.fileInput.click()// 将word文件保存到用户选择的路径中this.fileContent wordContent},saveFile() {// 获取用户选择的文件const file this.$refs.fileInput.files[0]// 如果用户取消选择则返回if (!file) {return}// 保存文件到用户选择的路径中FileSaver.saveAs(this.fileContent, file.name)}} } /script注意需要在项目中安装jspdf、html-docx-js和file-saver库。
http://www.yayakq.cn/news/5032/

相关文章:

  • 沂南建设局网站网站域名查询注册
  • 网站维护提示页面模板离我最近的物流公司
  • 在互联网上建设网站可选择的方案有领导高度重视门户网站建设
  • 官网设计比较好看的网站网站文章页301重定向怎么做
  • 吉林网站建设公司展厅装修效果图
  • 网站建设方案标书深圳公司注册登记中心
  • 怎么做网站自动响应那个网站做玉石最专业
  • 网盘网站建设设计专业自学网站
  • 肃宁县网站建设公司万网是什么网站
  • 怎么评价网站做的好坏个人网站名可以和别人一样吗
  • 网站开发询价表模板下载网站系统怎么做
  • wordpress有识图插件长沙谷歌优化
  • 网站后台维护一般要怎么做2345小游戏
  • 做百度网站那家好wordpress 自定义 分类
  • 怎么样自己做最简单的网站潍坊企业建站系统
  • 金华网站建设公司哪家好vs网站制作教程
  • 福建省建设职业管理中心网站小型办公室网络组建
  • 中国建筑官网首页seo线下培训课程
  • 绮思网站建设qswoo做 理财网站好
  • 网站开发和前端和数据媒体打开国外网站很慢
  • 深圳微商城网站设计制作wordpress 用ip访问
  • dz网站如何搬家虚拟主机可以干什么
  • html5 微信网站企业类展厅设计公司
  • 单页网站内链接黑白风格网站
  • 网站建设有什么看法网站电脑培训班附近有吗
  • windows搭建php网站盱眙在仕德伟做网站的有几家
  • 媒体网站的销售怎么做wordpress 数据库地址
  • 做的比较好网站有哪些一站式网站
  • 用wordpress做音乐网站德州市平原县建设局网站
  • 怎么做自己的网站弄商城佣金企业网站 带后台