当前位置:网站首页>Screenshot transferred to the background
Screenshot transferred to the background
2022-07-28 05:48:00 【I want to be a talker】
Send a screenshot of a part of the page to the back end
Detailed description of requirements
You need to put the histogram displayed on the page ( Or some preset area on other graphics or pages ) Take a screenshot and send it to the back end , The back end puts the pictures passed in from the front end into excel in , Automatic page download excel.
Realization
// Export pictures
handleExport() {
// Generate url
const canvas = document.createElement("canvas");// Create a canvas
let canvasBox = document.getElementById("export-region");// according to id Get what you want to intercept dom
const width = canvasBox.offsetWidth;
const height = canvasBox.offsetHeight;
canvas.width = width;
canvas.height = height;// Set the canvas to dom The width and height of
// When the generated page is vague , It can be amplified by a certain multiple , Through adjustment canvas The width and height of make it less clear
const context = canvas.getContext("2d");
context.scale(1, 1);
const options = {
backgroundColor: null,
canvas: canvas,
useCORS: true
};
html2canvas(canvasBox, options).then(canvas => {
let imgUrl = canvas.toDataURL("image/png");
// take base64 The file is converted to blob
let blob = dataURLtoBlob(imgUrl); // dataURL-> blob
let file = blobToFile(blob, " Screenshot .png"); // blob -> file
// Organizational parameters
let formData = new FormData();
// Add the binary file to formData in
formData.append("PictrueFile", file, " Screenshot .png");
exportPicture(formData).then(res => {
// above PictureFile The parameter name defined for the backend ,exportPicture To call the function of the back-end interface , It needs to be modified according to the actual situation
let resBlob = new Blob([res.data], {
type: "application/x-xlsx" });
let fileUrl = window.URL.createObjectURL(resBlob);
let link = document.createElement("a");
link.href = fileUrl;
link.setAttribute(
"download",
" Data and picture export _" + formatDate(+new Date(), "YYYY_MM_DD") + ".xlsx"
);//excel name ‘ Customize + current time ’
link.click();
});
});
},
// The two functions used dataURLtoBlob blobToFile
/** * take base64 Convert to blob */
function dataURLtoBlob(dataUrl){
var arr = dataUrl.split(","),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {
type: mime
});
}
/** * take blob Convert to file */
export const blobToFile = (theBlob, fileName) => {
theBlob.lastModifiedDate = new Date();
theBlob.name = fileName;
return theBlob;
}
边栏推荐
- ArcMap地图投影相关操作
- Arcgis Engine安装的若干问题
- You must configure either the server or JDBC driver (via the ‘serverTimezone)
- new,let,var,const以及暂时性死区,xml和json的区别
- 标准C语言总结4
- 冶金物理化学复习 -- 金属电沉积过程中的阴极极化,超电势以及阳极和阳极过程
- Solve the problem that Oracle cannot use more than 1000 in statements
- Custom JSON return data
- Annotation and grid addition of ArcGIS map making
- Review of metallurgical physical chemistry -- Fundamentals of chemical reaction kinetics
猜你喜欢
![[idea plug-in artifact] teaches you how to set all attributes in an entity class with one click of idea](/img/d6/4e69480c5ad5040ee48941ca0fcb37.png)
[idea plug-in artifact] teaches you how to set all attributes in an entity class with one click of idea

Zotero - a document management tool

wangeditor(@4.7.15)-轻量级的富文本编辑器

Global event bus

MYSQL之搭建数据库系列(一)——下载MYSQL

GD32F407 移植FreeRTOS+Lwip

Centos7 install MySQL 5.7

Review of metallurgical physical chemistry -- cathodic polarization, overpotential, anode and anode process in metal electrodeposition

SVG了解与绘图应用

【uni-app】uni-app中scroll-into-view的使用
随机推荐
全局事件总线
Microsoft Edge浏览器插件(1)
链表实现增删查改
结果填空 奖券数目(dfs * 数学公式)
结果填空 马虎的算式(暴力解决)
Database interview
Model builder of ArcGIS
TopK问题
HDU-1284:钱币兑换问题 推理+动态规划(dp)
uniapp问题:“navigationBarTextStyle“报错:Invalid prop: custom validator check failed for prop “navigat
Annotation and grid addition of ArcGIS map making
基于Easy CHM和VS的帮助文档制作
【uni-app】uni-app中scroll-into-view的使用
C语言走迷宫
DOM——页面的渲染、style属性操作、预加载与懒加载、防抖与节流
Review of metallurgical physical chemistry --- liquid liquid reaction kinetics
pytorch安装----CPU版的
new,let,var,const以及暂时性死区,xml和json的区别
树莓派WIFI一键连接配置
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid