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

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

相关推荐
ncj3934379067 小时前
【第1章 基础知识】1.8 在 Canvas 中使用 HTML 元素
canvas
Shi_haoliu9 小时前
前端vue2-完全前端生成pdf->pdf-lib,html2canvas+jspdf,原生打印,三种方式(打印带有echarts图的pdf)
前端·javascript·vue.js·git·pdf·echarts·html5
二壳9 小时前
将网页带格式转化为PDF
pdf
辣香牛肉面13 小时前
PDF电子发票数据提取至Excel
pdf·发票提取
CodeCraft Studio14 小时前
PDF处理控件Aspose.PDF教程:压缩 PDF 文档的完整指南
开发语言·python·pdf
IDRSolutions_CN14 小时前
如何将 PDF 文件中的文本提取为 YAML(教程)
java·经验分享·pdf·软件工程·团队开发
SEO-狼术14 小时前
Clarity and Context to PDF Files
pdf
zzc92114 小时前
PPT连同备注页(演讲者模式)一块转为PDF
pdf
課代表15 小时前
Acrobat Reader 无法在 Windows 11及10 中打开的5种修复方法
windows·adobe·pdf·adobe acrobat reader·修复·dc
yzhSWJ16 小时前
Excel 操作 转图片,转pdf等
java·pdf·excel