【笔记】当个自由的书籍收集者从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 小时前
Pdf转Word案例(java)
java·pdf·word·格式转换
小魏的马仔6 小时前
【java】使用iText实现pdf文件增加水印功能
java·开发语言·pdf
Wcowin6 小时前
Mkdocs页面如何嵌入PDF
前端·pdf·mkdocs
TextIn智能文档云平台9 小时前
TextIn ParseX重磅功能更新:支持切换公式输出形式、表格解析优化、新增电子档PDF去印章
java·图像处理·人工智能·算法·自然语言处理·pdf·ocr
IDRSolutions_CN1 天前
如何用Java读取PDF
java·经验分享·pdf·软件工程·团队开发
bu_shuo1 天前
Edge浏览器PDF字体显示错误
pdf·word·渲染错误
今天也想MK代码1 天前
zotero pdf中英翻译插件使用
pdf
just a little bit!1 天前
ORCAD打印pdf
pdf
至简电子1 天前
wrod生成pdf。[特殊字符]改背景
pdf