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

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

相关推荐
月巴月巴白勺合鸟月半5 分钟前
一次PDF文件的处理(一)
pdf·c#
弓.长.1 小时前
ReactNative for OpenHarmony项目鸿蒙化三方库:react-native-pdf — PDF文档查看器
react native·pdf·harmonyos
liulilittle2 小时前
范围随机算法实现
开发语言·c++·算法·lua·c·js
开开心心就好3 小时前
绿色版PDF多功能工具,支持编辑转换
人工智能·windows·pdf·ocr·excel·语音识别·harmonyos
月巴月巴白勺合鸟月半8 小时前
一次PDF文件的处理(二)
pdf·c#
开开心心就好8 小时前
免费无广告的礼金记账本,安卓应用
java·前端·ubuntu·edge·pdf·负载均衡·语音识别
优化控制仿真模型8 小时前
2015-2025年12月英语六级历年真题及答案PDF电子版(含听力音频)
经验分享·pdf
爱编程的小吴9 小时前
LangChain基础入门:DocumentLoader加载PDF/Markdown文档实战
python·langchain·pdf
软件工程小施同学9 小时前
区块链论文速读 CCF A--CCS 2025 (1) 附pdf下载
pdf·区块链
我命由我123451 天前
Element Plus 2.2.27 的单选框 Radio 组件,选中一个选项后,全部选项都变为选中状态
开发语言·前端·javascript·html·ecmascript·html5·js