gpt4 book ai didi

javascript - 将 html 表格转换为 word 文档或可编辑的 pdf

转载 作者:行者123 更新时间:2023-11-30 16:06:22 34 4
gpt4 key购买 nike

我一直在使用jquery datatablejsPDF , 用于导出 html table to pdf使用像

这样的代码
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
}

是否有 javascript 库可以将 html 表格导出为 word 文档(首选)或可编辑 pdf?

最佳答案

jsPdf 的作者用纯客户端 JavaScript 为 Microsoft Word 文档制作了一个文档生成器,名为 DOCX.js并推荐使用 Stephen Hardy 的 DOCX.js .

DOCX.js 取决于 JSZip支持粗体、斜体、下划线、删除线、下标、上标、字号、字体颜色、高亮、水平对齐等书写。对于阅读,它支持上述所有内容以及嵌入的 PNG。将来可能会支持表格和列表(带项目符号和编号),但目前不支持。

ZerdaH's Fork 的演示用法:

var docDOM = document.getElementById('example');

var docObject = docx.export(docDOM, // required DOM Object
{
creator: "Creator", // optional String
lastModifiedBy: "Last person to modify", // optional String
created: new Date(), // optional Date Object
modified: new Date() // optional Date Object
});

var link = document.createElement('a');
link.appendChild(document.createTextNode("Download Link Text"));
link.title = "Download Title";
link.download = "FilenameHere.docx";
link.href = docObject.href();
document.getElementById("example").appendChild(link);

关于javascript - 将 html 表格转换为 word 文档或可编辑的 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36983922/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com