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

【笔记】当个自由的书籍收集者从canvas得到png转pdf

最近有点迷各种古书,然后从 www.shuge.org 下载了各种高清的印本,快成db狂魔了…上面也有人在各种平台上分享,不胜感激…只是有些平台可以免费看但是没法下载… 反正你都canvas了,撸下来自己珍藏…

于是让qwen写了一段代码:

write a javascript function to trigger download a picture from a canvas image data. i mean there is a canvas with sth painted. i’d like to have a function to get its image data and convert the raw data into for example png file data array and trigger downloading the file from memory.

function downloadCanvasImage(canvas, filename = 'canvas-image.png', format = 'png') {// Get the image data URL from the canvasconst mimeType = format === 'png' ? 'image/png' : 'image/jpeg';const dataURL = canvas.toDataURL(mimeType);// Create a temporary link elementconst link = document.createElement('a');link.href = dataURL;link.download = filename;// Append the link to the body (required for Firefox)document.body.appendChild(link);// Programmatically click the link to trigger the downloadlink.click();// Remove the link from the DOMdocument.body.removeChild(link);
}

之后

const list = document.querySelectorAll('canvas.<classname>');
for (let i = 0; i < list.length; i ++) {downloadCanvasImage(list[i], `page${i+1}.png`);
}

然后再一个 image-to-pdf 就可以变成pdf存档了。大书库又多了几百GB…

把各种迷信的命相卜书籍看完,大致了解了古代历法五行阴阳历干支历(圭表测影、十月历、六龙历…),易经卦象…开始再看一遍医书,启动第二遍理解…

相关文章:

  • win11指定Microsoft Print To PDF的输出路径(电子书djvu转pdf输出路径)
  • java每日精进 5.07【框架之数据权限】
  • Zsh + iTerm2搭配使用教学,非常舒服,macOS
  • java CompletableFuture 异步编程工具用法2
  • SpringBoot学生宿舍管理系统开发实现
  • 中间件-RocketMQ
  • IPFS集群部署
  • 【JS逆向基础】并发爬虫
  • Linux复习笔记(一)基础命令和操作
  • 技术分享:Franka机器人新方案——双臂数据采集与适应性安装,带你探索具身智能的奥秘
  • C# NX二次开发:曲线和点位相关UFUN函数详解
  • 15_sysfsLinux内核模块
  • 在 R 中,清除包含 NA(缺失值)的数据
  • AOP封装进行批量的数据查询并填充
  • 探索智能体的记忆:类型、策略和应用
  • MySQL优化-MySQL常用查询命令
  • MATLAB三维可视化技术解析
  • 引用的使用
  • 什么是跨域,如何解决跨域问题
  • 脑图谱:脑机接口的必由之路——技术突破与产业转化的系统性思考
  • 非洲雕刻艺术有着怎样的“变形之美”
  • 巴基斯坦空袭印度多地空军基地,巴战机进入印领空
  • 来论|建设性推进缅北和平进程——中国的智慧与担当
  • 七大交响乐团“神仙斗法”,时代交响在上海奏出时代新声
  • 国家主席习近平同普京总统共见记者
  • 陕西澄城樱桃在上海推介,向长三角消费者发出“甜蜜之邀”