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

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

相关推荐
诸神缄默不语4 小时前
如何用Python处理文件:Word导出PDF & 如何用Python从Word中提取数据:以处理简历为例
python·pdf·word
i***66504 小时前
SpringBoot实战(三十二)集成 ofdrw,实现 PDF 和 OFD 的转换、SM2 签署OFD
spring boot·后端·pdf
Watermelo6176 小时前
为什么赋值过程会丢失this
开发语言·前端·javascript·vue.js·前端框架·es6·js
777VG8 小时前
Vue3+vue3-pdf-app@1.0.3实现加载 .pdf文件
前端·javascript·vue.js·pdf
ComPDFKit8 小时前
Salesforce原生PDF编辑的重要性:效率、合规性与用户体验
大数据·pdf·ux
Forever777777778 小时前
PDF瘦身,告别WPS收费压缩PDF
python·深度学习·pdf·免费
FreeBuf_8 小时前
高危Markdown转PDF漏洞,可通过Markdown前置元数据实现JS注入攻击(CVE-2025-65108,CVSS 10.0)
开发语言·javascript·pdf
q***48411 天前
SpringBoot实战(三十二)集成 ofdrw,实现 PDF 和 OFD 的转换、SM2 签署OFD
spring boot·后端·pdf
爱分享的鱼鱼1 天前
Vue.js 中实现局部彩条ConfettiEffect动效:采用canvas-confetti库
vue.js·canvas
SEO-狼术1 天前
Direct PDF Printing to .NET Applications
pdf