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

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

相关推荐
weixin_416667966 小时前
Stirling-PDF是一款完全开源免费、本地部署的全能PDF处理工具
pdf
开开心心就好7 小时前
PDF图片去水印软件,支持批量处理页面
前端·javascript·人工智能·智能手机·pdf·语音识别
2501_919749038 小时前
华为鸿蒙免费PDF工具—小羊免费PDF
华为·pdf·harmonyos·鸿蒙
SamChan909 小时前
PDF多语言翻译的格式还原技术拆解:从版面分析到内容重排的工程实现
python·ai·pdf·机器翻译
weixin_469273811 天前
如何在线把文字转为 pdf 文档
pdf
2601_963906781 天前
离线截图 OCR 识别:支持表格与 PDF 解析
pdf·ocr·软件需求
asdzx671 天前
Python 实现 PDF 文本查找与高亮标注
开发语言·python·pdf
laoban-yu1 天前
Word与PDF文档互转
pdf·word·文档转换
又吹风_Bassy2 天前
WhatsCanvas教程-第十一章:性能优化
性能优化·canvas·skia·2d渲染库·nanovg·whatscanvas·2d图形库
又吹风_Bassy2 天前
WhatsCanvas教程-第九章:窗口呈现与交互
canvas·opengl·skia·2d渲染库·nanovg·whatscanvas·2d图形库