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

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

相关推荐
伊织code16 小时前
pdftk - macOS 上安装使用
macos·pdf·pdftk
菜鸟-要努力1 天前
pdf文件转word免费使用几个工具
pdf·word
用户2519162427111 天前
Canvas之画图板
前端·javascript·canvas
量化风云2 天前
『量化人的概率 03』PDF is all you need
python·金融·pdf·概率论·量化交易·量化课程
GIS小小研究僧2 天前
免费PDF编辑软件 pdf24-creator 及其安装包
pdf
Python当打之年2 天前
工具分享05 | Python制作PDF合并拆分提取工具V1.0
python·pdf
EkihzniY3 天前
单层 PDF 与双层 PDF:一字之差,功能大不同
pdf·ocr
Dxy12393102163 天前
Python合并两个PDF文件
python·pdf
数据知道4 天前
将英文PDF文件完整地翻译成中文的4类方式
人工智能·学习·自然语言处理·pdf·机器翻译
dxnb224 天前
Datawhale+AI夏令营_让AI读懂财报PDF task2深入赛题笔记
人工智能·笔记·pdf