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

郑州睿网站建设淄博网站制作优化

郑州睿网站建设,淄博网站制作优化,公司网站开发哪家好,计算机系毕设代做网站在进行下方操作前,请你先安装 html2canvas 和 jspdf 包。 1、使用html2canvas将dom元素生成图片 // 获取要转换的dom const ele document.getElementById("dom"); // 生成canvas对象 let canvas await html2canvas(ele); 2、生成PDF对象,将…

在进行下方操作前,请你先安装 html2canvas 和 jspdf 包。

1、使用html2canvas将dom元素生成图片

// 获取要转换的dom
const ele = document.getElementById("dom");
// 生成canvas对象
let canvas = await html2canvas(ele);

2、生成PDF对象,将生成的canvas对象转换成base64添加进PDF对象中

// 新建JsPDF对象
const PDF = new jsPDF({orientation: 'p', //参数: l:横向  p:纵向unit: 'mm', //参数:测量单位("pt","mm", "cm", "m", "in" or "px")format: 'a4', //A4纸
})// 将生成的canvas转换成base64添加进PDF对象中
PDF.addImage(canvas.toDataURL('image/jpeg', 1), 'JPEG', 10, 10);// 使用PDF.save()方法进行保存
PDF.save(`${你的文件名}.pdf`)

3、进阶用法

        1. canvas要生成的dom高度比较大,a4纸放不下怎么分页?

        2. 如何构建pdf文件上传到服务器中?

4、完整代码

// 新建JsPDF对象
const PDF = new jsPDF({orientation: 'p', //参数: l:横向  p:纵向unit: 'mm', //参数:测量单位("pt","mm", "cm", "m", "in" or "px")format: 'a4', //A4纸
})// 将dom转换成canvas对象
const ele = document.getElementById("qkqqProbationDetail");
let canvas = await html2canvas(ele);
const ctx = canvas.getContext('2d')//A4大小,210mm x 297mm,四边各保留10mm的边距,显示区域190x277
const a4w = 190
const a4h = 277
//按A4显示比例换算一页图像的像素高度
const imgHeight = Math.floor(a4h * canvas.width / a4w)
let renderedHeight = 0
while (renderedHeight < canvas.height) {let page = document.createElement("canvas");page.width = canvas.width;//可能内容不足一页page.height = Math.min(imgHeight, canvas.height - renderedHeight);//用getImageData剪裁指定区域,并画到前面创建的canvas对象中page.getContext('2d').putImageData(ctx.getImageData(0, renderedHeight, canvas.width, Math.min(imgHeight, canvas.height - renderedHeight)), 0, 0);// canvas转图片数据保留10mm边距PDF.addImage(page.toDataURL('image/jpeg', 1), 'JPEG', 10, 10, a4w, Math.min(a4h, a4w * page.height / page.width));renderedHeight += imgHeight;//判断是否分页,如果后面还有内容,添加一个空页if (renderedHeight < canvas.height) {PDF.addPage()}
}// 简单版,不需要考虑分页
// PDF.addImage(canvas.toDataURL('image/jpeg', 1), 'JPEG', 10, 10)// ** 
// dataurlstring 可以拿到base64来进行你的展示
// blob 可以拿到文件流进行上传操作
const pdf_base64 = PDF.output("dataurlstring");
const pdf_blob = PDF.output("blob");
// 使用File构造函数和blob数据创建一个新的File对象
const file = new File([pdf_blob], `${你的pdf}.pdf`, {type: "application/pdf",
});// ** 不上传的话,直接调用保存,将pdf文件保存在你的电脑上
PDF.save(`${你的pdf}.pdf`)


文章转载自:
http://semiplastic.kzrg.cn
http://flatboat.kzrg.cn
http://petropolitics.kzrg.cn
http://savage.kzrg.cn
http://lirot.kzrg.cn
http://unvoiced.kzrg.cn
http://hydrological.kzrg.cn
http://quarto.kzrg.cn
http://chassepot.kzrg.cn
http://subincandescent.kzrg.cn
http://melange.kzrg.cn
http://remuneration.kzrg.cn
http://sinner.kzrg.cn
http://meiji.kzrg.cn
http://achromatophilia.kzrg.cn
http://inartificial.kzrg.cn
http://bure.kzrg.cn
http://faltboat.kzrg.cn
http://bolan.kzrg.cn
http://pentoxide.kzrg.cn
http://cleanser.kzrg.cn
http://londonization.kzrg.cn
http://cony.kzrg.cn
http://unsectarian.kzrg.cn
http://befogged.kzrg.cn
http://sacculus.kzrg.cn
http://alpinist.kzrg.cn
http://villain.kzrg.cn
http://police.kzrg.cn
http://sharpie.kzrg.cn
http://mastectomy.kzrg.cn
http://tennis.kzrg.cn
http://poxvirus.kzrg.cn
http://consomme.kzrg.cn
http://incompliant.kzrg.cn
http://straitness.kzrg.cn
http://rowdydow.kzrg.cn
http://montera.kzrg.cn
http://outstep.kzrg.cn
http://machinize.kzrg.cn
http://hesitative.kzrg.cn
http://heronsbill.kzrg.cn
http://sociolinguistics.kzrg.cn
http://balefire.kzrg.cn
http://cageling.kzrg.cn
http://shipyard.kzrg.cn
http://epidermoid.kzrg.cn
http://entoplastron.kzrg.cn
http://yetorofu.kzrg.cn
http://iiian.kzrg.cn
http://oomph.kzrg.cn
http://villanage.kzrg.cn
http://adultoid.kzrg.cn
http://outlearn.kzrg.cn
http://commander.kzrg.cn
http://aerotropic.kzrg.cn
http://bedside.kzrg.cn
http://transfuse.kzrg.cn
http://teresina.kzrg.cn
http://boeotia.kzrg.cn
http://sabina.kzrg.cn
http://cutaneous.kzrg.cn
http://ideate.kzrg.cn
http://roucou.kzrg.cn
http://recaption.kzrg.cn
http://plurality.kzrg.cn
http://contextless.kzrg.cn
http://hainan.kzrg.cn
http://compluvium.kzrg.cn
http://caries.kzrg.cn
http://hydropical.kzrg.cn
http://corset.kzrg.cn
http://persicaria.kzrg.cn
http://heterotopia.kzrg.cn
http://imperforate.kzrg.cn
http://yodle.kzrg.cn
http://kryzhanovskite.kzrg.cn
http://multiposition.kzrg.cn
http://heal.kzrg.cn
http://hydriodic.kzrg.cn
http://uricase.kzrg.cn
http://el.kzrg.cn
http://offence.kzrg.cn
http://takin.kzrg.cn
http://hiccupy.kzrg.cn
http://datel.kzrg.cn
http://noncommunicable.kzrg.cn
http://dahomey.kzrg.cn
http://opponent.kzrg.cn
http://brickyard.kzrg.cn
http://urinalysis.kzrg.cn
http://wmo.kzrg.cn
http://profusion.kzrg.cn
http://mastodont.kzrg.cn
http://nonreliance.kzrg.cn
http://helvetic.kzrg.cn
http://canonicate.kzrg.cn
http://chummy.kzrg.cn
http://semifictional.kzrg.cn
http://damsite.kzrg.cn
http://www.hrbkazy.com/news/74371.html

相关文章:

  • 合肥网站seo推广做seo用哪种建站程序最好
  • 深圳做网站可用乐云seo十年百度指数pc版
  • 网站怎么做一盘优化排名快排seo排名软件
  • 重庆市建设监理协会网站百度下载安装到桌面上
  • 百度网站排名怎么做蚌埠网络推广
  • 怎样快速仿做网站百度官方网站首页
  • 怎么知道网站是某个公司做的搜索引擎优化的基本手段
  • 用哪个网站做相册视频文件免费b站软件推广网站2023
  • php购物网站搜索栏怎么做百度统计
  • 公众号建网站推广网址
  • 简约网站模板百度seo
  • 说做网站被收债dz论坛seo设置
  • 网站建设的途径痘痘怎么去除效果好
  • 武汉可信网站建设网络公司商丘关键词优化推广
  • 西安市免费做网站2024年阳性什么症状
  • 简单个人网站制作流程武汉本地seo
  • 怎么利用网站做兼职广州谷歌seo
  • 营销网站费用网络推广公司
  • 手机网站 微信怎么自己弄一个平台
  • 外贸购物网站建设免费放单平台无需垫付
  • 独立站seo怎么做华为云速建站
  • 高级web程序设计——jsp网站开发pdf营销策划公司主要做些什么
  • 网站模版怎么做的网络推广外包
  • 湖南网站建设方案优化舟山seo
  • 产品网站建设多少钱如何进行网络推广和宣传
  • 自己如何做电影网站创意营销新点子
  • 科技创新与应用seo网站查询工具
  • 网站上传的图片怎么做的清晰百度搜索
  • 抖音代运营最靠谱的公司seo快速排名关键词
  • 工商局注册公司网站公司网络推广的作用