仲灏小栈 仲灏小栈
首页
大前端
后端&运维
其他技术
生活
关于我
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

仲灏

诚意, 正心, 格物, 致知
首页
大前端
后端&运维
其他技术
生活
关于我
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 嵌入式

  • Android

  • 编辑器

  • 产品&设计

  • 测试

  • 虚拟机

  • 算法

  • 网络

  • 安全

  • Nas

  • 硬件

  • CDCI

  • 破解

    • 技能人才评价工作网pdf文件下载方法
      • 方法一: 元素截图
      • 方法二:直接取文件源码处理
  • 建筑

  • clash-rule最佳配置
  • Untitled
  • 其他技术
  • 破解
仲灏
2023-09-17
目录

技能人才评价工作网pdf文件下载方法

该网站和该技术仅仅学习使用, 若有侵权和侵犯利益, 可联系我删除

# 方法一: 元素截图

/*
 * @Author: 仲灏<izhaong@outlook.com>🌶🌶🌶
 * @Date: 2023-08-22 17:31:20
 * @LastEditTime: 2023-08-23 00:35:41
 * @LastEditors: 仲灏<izhaong@outlook.com>🌶🌶🌶
 * @Description:  
 * @FilePath: \js\batchCanvas2picAnDownload.js
 */
/**
 * @Description: 批量canvas转图片并下载脚本
 * @author 仲灏 izhaong@outlook.com
 * @date 2023/8/22
 */

// 1. 获取所有的canvas元素并有序存储
// 2. 批量循环转换为高清图片并有序命名
// 3. 批量触发下载

const getCanvasDom = () => {
  const viewer = document.querySelector('div#viewer.pdfViewer');
  const childrenList = viewer.childNodes;

  return Array.from(childrenList).map((ce) => {
    return {
      ariaLabel: ce.ariaLabel,
      canvasDom: ce.querySelector('div.canvasWrapper > canvas'),
    };
  });
};
console.table(getCanvasDom());
const canvasList = getCanvasDom();

const getPixelRatio = (context) => {
  const backingStore =
      context.backingStorePixelRatio ||
      context.webkitBackingStorePixelRatio ||
      context.mozBackingStorePixelRatio ||
      context.msBackingStorePixelRatio ||
      context.oBackingStorePixelRatio ||
      context.backingStorePixelRatio || 1;
  return (window.devicePixelRatio || 1) / backingStore;
}

const downLoadImage = (canvas,name) => {
  if(!canvas || !name) return
  const a = document.createElement("a");
  a.href = canvas.toDataURL('image/jpeg', 2);
  a.download = name;
  a.click();
}

for (let i = 0; i < canvasList.length; i++) {
  const canvasItem = canvasList[i]
  const {ariaLabel, canvasDom} = canvasItem || {}
  // width: 582px; height: 816px;
  // const ctx = canvasDom.getContext('2d');
  // const ratio = getPixelRatio(ctx);
  canvasDom.style.scale = 10
  // canvasDom.width = '5820px';
  // canvasDom.height = '8160px';
  // ctx.drawImage(image, 20* ratio, 20* ratio, 260* ratio, 460* ratioÏ);
  // const base64 = cvs.toDataURL("image/png", 2.0);
  // console.log({ariaLabel, canvasDom})
  // ((cDom, label) => {
    downLoadImage(canvasDom, ariaLabel)
  // })(canvasDom, ariaLabel)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

# 方法二:直接取文件源码处理

http://biaozhun.osta.org.cn/index.html

  • 获取文件base64编码

  • img

  • base64转换为PDF

  • https://products.aspose.app/pdf/zh/conversion/base64-to-pdf

  • img

上次更新: 2023/09/17, 20:06:58
环境
自建房_2混凝土施工技术准备

← 环境 自建房_2混凝土施工技术准备→

最近更新
01
vim日常使用记录
04-02
02
滑动窗口最大值
04-02
03
有效的字母异位词
04-02
更多文章>
Theme by Vdoing | Copyright © 2021-2025 izhaong | github | 蜀ICP备2021031194号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式