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

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

相关推荐
Charlie_lll1 小时前
LibreOffice 实现 Word 转 PDF
java·spring boot·pdf·word
Java后端的Ai之路2 小时前
【AI大模型开发】-基于向量数据库的PDF智能问答系统(实战)
人工智能·pdf·向量数据库·智能问答系统
zhangfeng11331 天前
[图书推荐]1000本电子书的开源项目 pdf
pdf
SunnyDays10111 天前
Java 旋转 PDF 页面完整指南(含示例)
java·pdf·pdf页面旋转·旋转pdf页面
JaredYe1 天前
纯 Node.js 的 PDF 转 Markdown 方案:支持图片解析的pdf2md库 `node-pdf-to-markdown`
pdf·node.js·markdown·md·pdf2md
wxl7812271 天前
基于Cognee实现PDF图文并茂解析与检索的实践方案
pdf·ocr·图文并茂·cognee
林恒smileZAZ1 天前
前端 HTML 转 PDF
前端·pdf·html
好像不对劲1 天前
python去除pdf白边
开发语言·python·pdf·kindle
我要学好英语2 天前
知网下载的.caj文件怎么转成.pdf文件
pdf
墨痕诉清风2 天前
文件上传漏洞(PDF文件)
安全·web安全·pdf