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

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

相关推荐
开开心心就好1 小时前
轻松加密文件生成exe,无需原程序解密
linux·运维·服务器·windows·pdf·harmonyos·1024程序员节
我在这里呀3 小时前
免费在线PDF翻译工具(保留排版,可导出Word)
pdf·word
软件工程小施同学3 小时前
区块链论文速读 CCF A--VLDB 2025 (2) 附pdf下载
pdf·区块链
❀͜͡傀儡师4 小时前
Spring Boot 实现PDF水印的完整指南
spring boot·后端·pdf
大黄说说21 小时前
Python 实战指南:一键批量旋转 PDF 页面方向
开发语言·python·pdf
Jack.Huangjh2 天前
ABAP PDF
pdf
北极象2 天前
Flying-Saucer HTML到PDF渲染引擎核心流程分析
前端·pdf·html
一只酸奶牛^_^2 天前
java实现pdf添加水印
java·pdf
还是叫明2 天前
将PDF每一页导出一张图片(C#,.NET)
pdf
E_ICEBLUE2 天前
Python 实现 PDF 表单域的自动化创建与智能填充
python·pdf·自动化·表单域