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

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

相关推荐
uuai2 小时前
vue导出pdf
前端·vue.js·pdf
Sour2 小时前
产品说明书翻译成英文怎么保留排版?PDF、Word、外贸资料处理清单
pdf·word
winfredzhang13 小时前
为长阅读而生:我做了一个「安静」的 PDF 阅读器
pdf·html
100个铜锣烧1 天前
文档处理管线:从PDF到向量——RAG系统的“第一道关口”
pdf
asdzx671 天前
在 React 中轻松实现 PDF 转 Word:纯前端 WASM 方案实战
前端·react.js·pdf
Lyn_Li2 天前
扫描 PDF 歪了怎么办?用 6 种检测方法做本地批量扶正(附开源工具)
python·pdf·ocr·tesseract·开源工具·文档处理·本地处理·扫描件纠偏
Mr.Daozhi2 天前
从零构建 AI 学术论文助手(四):PDF.js 实时截图 + Gemini 视觉分析
javascript·人工智能·pdf·canvas·pdf.js·gemini
wenxin77wx4 天前
3步部署OlmOCR:一行命令将PDF转为LLM训练数据
pdf·- olmocr
2501_930707784 天前
PDF 转 Markdown:在线与离线转换完整指南
pdf
ShiXZ2134 天前
PDF-OCR文件识别篇(七):数据入库
java·pdf·json·ocr·springboot