【笔记】当个自由的书籍收集者从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.

js 复制代码
function downloadCanvasImage(canvas, filename = 'canvas-image.png', format = 'png') {
    // Get the image data URL from the canvas
    const mimeType = format === 'png' ? 'image/png' : 'image/jpeg';
    const dataURL = canvas.toDataURL(mimeType);

    // Create a temporary link element
    const 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 download
    link.click();

    // Remove the link from the DOM
    document.body.removeChild(link);
}

之后

js 复制代码
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...

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

相关推荐
XLYcmy18 小时前
PDF 论文处理器 — 改进方向与建议文档
python·pdf·llm·agent·dify·rag·harness
福兮说1 天前
canvas 旋转图片的六个坑:四角被裁、Math.ceil 多出 1px 黑边、JPG 角发黑、翻转方向反了
前端·javascript·图像处理·canvas
XLYcmy2 天前
PDF 论文处理器 — 优势与功能文档
大数据·python·网络安全·pdf·dify·rag·漏洞检测
闭包不眠2 天前
PDF文字提取交付前该检查什么
运维·服务器·图像处理·人工智能·计算机视觉·pdf
Latchh2 天前
PDF提取到文字后怎样发现乱码
图像处理·人工智能·计算机视觉·pdf
格数致用2 天前
01 - Luckysheet电子表格技术原理与架构深度解析
canvas·luckysheet·企业级报表
XLYcmy2 天前
PDF 论文处理器 — 技术报告文档
数据库·python·网络安全·pdf·embedding·dify·rag
deepseek232 天前
PDF 涂黑失效拆解:谷歌数据中心 52.65 兆瓦与 7.65 亿加仑的账本,被一次复制粘贴揭开
人工智能·pdf·数据中心
2601_949950632 天前
练题簿在线免费刷题 从资料整理到考前自测
面试·职场和发展·pdf·word·刷题
福兮说2 天前
设计稿是 #4A7C6F,页面量出来是 #4B7C6F:HEX、HSL、透明度、canvas 来回转的七个坑
前端·javascript·css·canvas